R
Richard
First question - let's get this out of the way since it might be the
solution to all my woes: Does it make sense to have a .cpp file for a
class that is declared as having pure virtual functions in its .h file?
Here's my predicament. I'll put this in general terms since it's
happening across several classes.
I have a base class, let's say it's named A. In A.h I DECLARE several
pure virtual ( = 0) functions, a virtual destructor, and a constructor.
Note that each of these is terminated with a semicolon, hence they're
not DEFINED. There is also a file A.cpp which defines the constructor
and destructor with empty curly braces. A.cpp and A.h compile into a
library file (.a) with GCC without errors.
There's a class B that derives class A. All of the pure virtual
functions are overridden by B. Class B also has a default constructor
(no parameters) and destructor. Class B compiles into a library
without error also.
When I go to link my executable I include the two resulting libraries.
The linker produces the error "undefined reference to A::A()" which is
said to occur in the constructor for class B. I've ensured that the
folders containing A.h and B.h are in the "include search path", and
I've ensured that the libraries containing A and B are included during
linking.
solution to all my woes: Does it make sense to have a .cpp file for a
class that is declared as having pure virtual functions in its .h file?
Here's my predicament. I'll put this in general terms since it's
happening across several classes.
I have a base class, let's say it's named A. In A.h I DECLARE several
pure virtual ( = 0) functions, a virtual destructor, and a constructor.
Note that each of these is terminated with a semicolon, hence they're
not DEFINED. There is also a file A.cpp which defines the constructor
and destructor with empty curly braces. A.cpp and A.h compile into a
library file (.a) with GCC without errors.
There's a class B that derives class A. All of the pure virtual
functions are overridden by B. Class B also has a default constructor
(no parameters) and destructor. Class B compiles into a library
without error also.
When I go to link my executable I include the two resulting libraries.
The linker produces the error "undefined reference to A::A()" which is
said to occur in the constructor for class B. I've ensured that the
folders containing A.h and B.h are in the "include search path", and
I've ensured that the libraries containing A and B are included during
linking.