It is referenced and I still get undefined reference issue
class base_rec {
public:
base_rec():str(" "){};
base_rec(string contentstr):str(contentstr){};
void showme() const;
protected:
string str;
};
class u_rec:public base_rec {
public:
u_rec():base_rec("undergraduate records"){};
void showme() { cout << "showme() function of u_rec class\t"
<< str << endl;}
};
class g_rec:public base_rec {
public:
g_rec():base_rec("graduate records"){};
void showme() { cout << "showme() function of g_rec class\t"
<< str << endl;}
};
int main() {
base_rec *brp[2];
brp[1] = new u_rec;
brp[2] = new g_rec;
for (int i=0; i<2; i++) {
brp[i]->showme();
}
}
Error Message:
main.cpp:(.text+0x58): undefined reference to `base_rec::showme() const' collect2: error: ld returned 1 exit status.
How can I fix it! the showme() is defined in base_rec
from Recent Questions - Stack Overflow https://ift.tt/3eJfxAC
https://ift.tt/eA8V8J
Comments
Post a Comment