class B
{
public:
// . . .
virtual void f() = 0;
};
int main() { B b1, b2; /*. . .*/ }
Second,
is it preferable to separate implementation and specification in software? like, it is preferable to place a template class definition in a “header” file, the template implementation of the member functions in an implementation file. The implementation should be compiled separately and linked to the application?
First: Nope. Setting a function to 0 makes the class abstract, you can't create instances of abstract classes.
Second: You can apply this to pretty much anything in C++. Unless you have extremely little code you would do function definition and declaration in separate files. First this makes organizing the code easier, second it reduces the compile time of large projects, and third it makes it easier to re use code later on.
Second,
is it preferable to separate implementation and specification in software? like, it is preferable to place a template class definition in a “header” file, the template implementation of the member functions in an implementation file.
hanst99 wrote:
Second: You can apply this to pretty much anything in C++...
apart from templates...
[35.12] Why can't I separate the definition of my templates class from its declaration and put it inside a .cpp file?
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12