<div dir="ltr">i am having problems compiling the following code:<br>====================================<br><br>#if 1<br>template <class T> class c1 {};<br>template <class T> class c2 : public c1<T> { public: c2(T &a); };<br>
#else<br>template <class T> class c1;<br>template <class T> class c2;<br>#endif<br><br>template <> class c1<int><br>{<br> int m_a;<br> public:<br> c1():m_a(0) {};<br> c1(int a):m_a(a) {};<br>
c1(int &a):m_a(a) {};<br> void set(const int a) {m_a=a;};<br> const int get(void) const {return m_a;};<br> c2<int> gen_c2(int a)<br> {<br> c2<int> ret(a);<br>
return ret;<br> }<br> const c1<int> &operator=(const c1<int> &other) {set(other.get()); return *this;};<br>};<br><br>template <> class c2<int> : public c1<int><br>
{<br>public:<br> c2(int &a):c1(a) {};<br>};<br><br>int main()<br>{<br> c1<int> a;<br> c2<int> b=a.gen_c2();<br>}<br>===========================================<br>if i compile it, i get:<br>
file.cpp:27: error: specialization of ‘c2<int>’ after instantiation<br><br>if on the other hand i change the #if 1 to #if 0, i get:<br>file.cpp: In member function ‘c2<int> c1<int>::gen_c2(int)’:<br>file.cpp:20: error: return type ‘struct c2<int>’ is incomplete<br>
<br><br></div>