c++ - Class Template Object cannot be created -


i using templates in 1 of classes, reason, when create object, error getting following: argument list class template "test" missing.

template <class t> class test {  private:       t variable;   public:      test(){cout << "constructor called" << endl;} }; 

in main.cpp

test object; 

compiler displays following: 'test' : use of class template requires template argument list.

template <class t> test<t>::test()  {   cout << "constructor called" << endl; } 

that did not work

you have specify type want instantiate class template. example:

  test<int> object; 

think how use class templates std library vectors, have specify type such int, e.g. vector<int> . same rationale that.

for constructor definition, should work, however, 1 point have put declaration , definition in same header file, otherwise, compiler cannot find definition. (there techniques can separate declaration , definition in different files, "export" , "#include cpp file" @ end of header file)


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -