Ich habe eine Konstante struct timespec
Mitglied in meiner Klasse. Wie soll ich es initialisieren?C++ Konstante Struktur Mitglied Initialisierung
Die einzige verrückte Idee, die ich bekommen habe, ist, meinen eigenen timespec
abzuleiten und ihm einen Konstruktor zu geben.
Vielen Dank!
#include <iostream>
class Foo
{
private:
const timespec bar;
public:
Foo (void) : bar (1 , 1)
{
}
};
int main() {
Foo foo;
return 0;
}
Compilation finished with errors: source.cpp: In constructor 'Foo::Foo()': source.cpp:9:36: error: no matching function for call to 'timespec::timespec(int, int)' source.cpp:9:36: note: candidates are: In file included from sched.h:34:0, from pthread.h:25, from /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/i686-pc-linux-gnu/bits/gthr-default.h:41, from /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/i686-pc-linux-gnu/bits/gthr.h:150, from /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, from /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43, from /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, from source.cpp:1: time.h:120:8: note: timespec::timespec() time.h:120:8: note: candidate expects 0 arguments, 2 provided time.h:120:8: note: constexpr timespec::timespec(const timespec&) time.h:120:8: note: candidate expects 1 argument, 2 provided time.h:120:8: note: constexpr timespec::timespec(timespec&&) time.h:120:8: note: candidate expects 1 argument, 2 provided
Haben Sie versucht, es gerade zu initialisieren? –
Sicher, ich tat es. Und ich habe einen Fehler bekommen. Bearbeitete die Frage. – Kolyunya
Ich weiß nicht, Jungs, warum Sie mich unten abstimmen, aber ich konnte einfach nicht die richtige Syntax finden ... – Kolyunya