c++ - template specialization implementation -



c++ - template specialization implementation -

i have implement template specialization, in implementing constructor specialized template class compiler generates errors. next code:

#include <iostream> using namespace std; // class template template <typename t> class mycontainer { t element; public: mycontainer (t arg); t increment () {return ++element;} }; // class template specialization template <> class mycontainer <void> { int element; public: mycontainer (int arg); char uppercase () { homecoming element; } }; template<typename t> mycontainer<t>::mycontainer(t arg){ cout << "hello t" << endl; } template<typename t> mycontainer<void>::mycontainer(int arg){ cout << "hello empty" << endl; } int main () { mycontainer<int> myint (7); mycontainer<void> myvoid (6); cout << myint.increase() << endl; homecoming 0; }

the code generate these errors:

test.cpp:31:22: error: prototype ‘mycontainer<void>::mycontainer(int)’ not match in class ‘mycontainer<void>’ test.cpp:16:26: error: candidates are: mycontainer<void>::mycontainer(const mycontainer<void>&) test.cpp:19:5: error: mycontainer<void>::mycontainer(int)

any clue on how resolve these errors ?

mycontainer<void> not template, , neither constructor, constructor definition should be:

mycontainer<void>::mycontainer(int arg){ cout << "hello empty" << endl; }

c++ templates

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -