M
Maciej Zobniow
Hi everybody!
I have problem with usage of inheritance and templates in my program
compiled under g++.
I have a base class A:
template<class T>
class A {
public:
A();
A(const A& orig);
virtual ~A();
private:
};
and child class B:
clacc B : public A<uint8_t>{
public:
B();
B(const B& orig);
~B();
}
The class A is initializing a structure, then B adds some buffers to the
structure. In implementation of construction of B I can write:
B::B() : A<uint8_t>(){
....
}
ant this works.
The problem happens in destructor. As I read in all books and
turtorials, destructor of A is called just after destructor of B
finished. Then I've implemented the destructor of B in the way that it
frees only buffers allocated in B(). The destructor of A do the rest.
As I can't write similar to constructor:
B::~B():~A<uint8_t>(){...}
in my code I have:
B::~B(){
....
}
Program compiles, but linking fails with a message:
undefined reference to A::~A<unsigned char>()
I guess that if compiler do not see any implicit reference to
A::~A<uint8_>() it's do not compile the specialization of the template.
How to force the compiler to compile the specialization in the best way?
Thanks
Maciek
I have problem with usage of inheritance and templates in my program
compiled under g++.
I have a base class A:
template<class T>
class A {
public:
A();
A(const A& orig);
virtual ~A();
private:
};
and child class B:
clacc B : public A<uint8_t>{
public:
B();
B(const B& orig);
~B();
}
The class A is initializing a structure, then B adds some buffers to the
structure. In implementation of construction of B I can write:
B::B() : A<uint8_t>(){
....
}
ant this works.
The problem happens in destructor. As I read in all books and
turtorials, destructor of A is called just after destructor of B
finished. Then I've implemented the destructor of B in the way that it
frees only buffers allocated in B(). The destructor of A do the rest.
As I can't write similar to constructor:
B::~B():~A<uint8_t>(){...}
in my code I have:
B::~B(){
....
}
Program compiles, but linking fails with a message:
undefined reference to A::~A<unsigned char>()
I guess that if compiler do not see any implicit reference to
A::~A<uint8_>() it's do not compile the specialization of the template.
How to force the compiler to compile the specialization in the best way?
Thanks
Maciek