I get a weird bug: "error: cannot declare variable ‘use’ to be of abstract type ‘test’", any idea where it is coming from ?
1 2 3 4 5 6 7 8 9 10 11
// Note: test is the name of class inside test.h file and use is the object
a.cpp: In function ‘int main()’:
a.cpp:20:17: error: cannot declare variable ‘use’ to be of abstract type ‘test’
A use("q1");
^
compilation terminated due to -Wfatal-errors.
<builtin>: recipe for target 'a' failed
make: *** [a] Error 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// a.cpp file
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include "Q.h"
#include "test.h"
usingnamespace std;
int main(){
// Note: test is the name of class inside test.h file and use is the object
string q1 = "How are you?";
test use(q1);
use.print();
return 0;
}
@gunnerfunner, yes you are right. I didn't know how to write the code for one of the functions in test.h, so I comment it out, but virtual function itself existed inside Q.h, so I had to comment that as well. I did it and it worked!
rather than say 'override the base class pure virtual function within the derived class' it might be better to say 'provide an implementation for the base class pure virtual function within the derived class' as this function is not implemented in the base class anyways