another c++ q (with specialization and inheritance )
Erez D
erez0001 at gmail.com
Tue Apr 28 10:03:28 IDT 2009
i am having problems compiling the following code:
====================================
#if 1
template <class T> class c1 {};
template <class T> class c2 : public c1<T> { public: c2(T &a); };
#else
template <class T> class c1;
template <class T> class c2;
#endif
template <> class c1<int>
{
int m_a;
public:
c1():m_a(0) {};
c1(int a):m_a(a) {};
c1(int &a):m_a(a) {};
void set(const int a) {m_a=a;};
const int get(void) const {return m_a;};
c2<int> gen_c2(int a)
{
c2<int> ret(a);
return ret;
}
const c1<int> &operator=(const c1<int> &other) {set(other.get());
return *this;};
};
template <> class c2<int> : public c1<int>
{
public:
c2(int &a):c1(a) {};
};
int main()
{
c1<int> a;
c2<int> b=a.gen_c2();
}
===========================================
if i compile it, i get:
file.cpp:27: error: specialization of ‘c2<int>’ after instantiation
if on the other hand i change the #if 1 to #if 0, i get:
file.cpp: In member function ‘c2<int> c1<int>::gen_c2(int)’:
file.cpp:20: error: return type ‘struct c2<int>’ is incomplete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20090428/74cdd743/attachment.html>
More information about the Linux-il
mailing list