C ++ Konstante Initialisierung von Strukturelementen
Ich habe eine Konstantestruct timespec
Mitglied in meiner Klasse. Wie soll ich es initialisieren?
Die einzige verrückte Idee, die ich hatte, war, meine eigene abzuleitentimespec
und gib ihm einen Konstruktor.
Vielen Dank!
#include <iostream>
class Foo
{
private:
const timespec bar;
public:
Foo ( void ) : bar ( 1 , 1 )
{
}
};
int main() {
Foo foo;
return 0;
}
Kompilierung mit Fehlern beendet: source.cpp: Im Konstruktor 'Foo :: Foo ()': source.cpp: 9: 36: Fehler: Keine passende Funktion für den Aufruf von 'timespec :: timespec (int, int)' source.cpp : 9: 36: Hinweis: Kandidaten sind: In Datei enthalten von sched.h: 34: 0, von pthread.h: 25, von /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/. ./../../../include/c++/4.7.2/i686-pc-linux-gnu/bits/gthr-default.h:41, von / usr / lib / gcc / i686-pc-linux -gnu / 4.7.2 /../../../../ include / c ++ / 4.7.2 / i686-pc-linux-gnu / bits / gthr.h: 150 aus / usr / lib / gcc /i686-pc-linux-gnu/4.7.2/../../../include/c++/4.7.2/ext/atomicity.h:34, from / usr / lib / gcc / i686 -pc-linux-gnu / 4.7.2 /../../../../ include / c ++ / 4.7.2 / bits / ios_base.h: 41, von / usr / lib / gcc / i686-pc -linux-gnu / 4.7.2 /../../../../ include / c ++ / 4.7.2 / ios: 43, von /usr/lib/gcc/i686-pc-linux-gnu/4.7 .2 /../../../../ include / c ++ / 4.7.2 / ostream: 40, from /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/../ ../../../include/c++/4.7.2/iostream:40, aus source.cpp: 1: time.h: 120: 8: note: timespec :: timespec () time.h: 120: 8: hinweis: kandidat Erwartet 0 Argumente, 2 angegeben time.h: 120: 8: Anmerkung: constexpr timespec :: timespec (const timespec &) time.h: 120: 8: Anmerkung: Kandidat erwartet 1 Argument, 2 angegeben time.h: 120: 8: note: constexpr timespec :: timespec (timespec &&) time.h: 120: 8: note: kandidat erwartet 1 argument, 2 angegeben