this question has answer here:
i want initialize array of class contains const member must initialize @ construction.
#include <iostream> class { private: const int var_; public: a(const int var) : var_(var){}; int getvar(){return var_;} }; class b { private: tab[2]; public: b() : tab{2,5} {}; // trick should here, think ! int geta(int index) { return tab[index].getvar();} }; int main(void) { b b; // constraint : dynamic allocation not allowed std::cout << b.geta(0) << std::endl; return 0; }
this code not compile because constructor class b not right. help, nicolas
the command
g++ -std=c++11 1.cpp
compiles code above fine. running 1.exe
prints 2
in console.
p.s: g++.exe (gcc) 4.9.0 20130616 (experimental)
Comments
Post a Comment