Inheritance question

I used to be good in these but for anymore. I have following code:

class A {
public:
A(){}
void show(){
cout << test << endl;
}
};

class B: public A {
public:
B(){}
void myFunc(){
show();
Other code...
}
};


Inside main:
B b;
b.myFunc();


I am getting ‘undefined reference to Show()’. Am I doing anything wrong. Public function in my base class should be accessible in my derived class. Right?
Also I am getting 'undefined reference to A:A()' as well. I am getting too old for C++.
Did you include class A's header file in class B' header file?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;

class A {
 public:
   A(){}
   void show(){
      cout << "test" << endl;
   }
};

class B: public A {
 public:
   B(){}
   void myFunc(){
      show();
   }
};


int main(){
   B b;
   b.myFunc();
   return 0;
}
This compiles with no errors. Try it.
What code exactly are you compiling?
Last edited on
Topic archived. No new replies allowed.