1
Vývoj / Re:C++ inicializácia immutable typov
« kdy: 09. 12. 2020, 02:50:21 »
Bohužel nelze kombinovat uživatelský konstruktor a inicializaci jako v C (aggregate initialization).
https://en.cppreference.com/w/cpp/language/aggregate_initialization
Šlo by to obejít vytvořením statické metody místo konstruktoru, např.:
https://en.cppreference.com/w/cpp/language/aggregate_initialization
Citace
An aggregate is one of the following types:
class type (typically, struct or union), that has
no user-declared or inherited constructors
Šlo by to obejít vytvořením statické metody místo konstruktoru, např.:
Kód: [Vybrat]
struct FileTimesInfo
{
const __time64_t LastAccessTime;
const __time64_t LastModificationTime;
const __time64_t LastStatusChangeTime;
constexpr static FileTimesInfo create(const struct _stati64& stat) noexcept
{
return FileTimesInfo{
.LastAccessTime = stat.st_atime,
.LastModificationTime = stat.st_mtime,
.LastStatusChangeTime = stat.st_ctime
};
}
};