Friday, 15 January 2010

c++ - Expect a type specifier when Templated class instance used in another class as member variable -



c++ - Expect a type specifier when Templated class instance used in another class as member variable -

i have 2 classes , b. template class , has constructor 1 integer argument. , class b uses a's instance int template argument. problem says type expected when compile program.

here program.

template <typename t> class { public: a(std::size_t max_size) { } }; class b { a<int> list(100); };

i getting compilation problem in

a<int> list(100);

line.

thanks in advance.

when compiler parses line

a<int> list(100);

it thinks trying declare function named list homecoming type a<int>. tries parse contents within parantheses find argument types, default values, etc. expects find type instead finds number

i'm guessing meant use:

a<int> list[100];

which declares list array of 100 a<int>s.

if meant utilize 100 parameter constructor of a<int>, you'll have use:

class b { b() : list(100) {} a<int> list; };

c++ visual-c++

No comments:

Post a Comment