Digital
Learning C++
- Joined
- Jul 15, 2018
- Messages
- 57
- Solutions
- 1
- Reaction score
- 12
I am learning C++ and wondered when its appropriate to use pointers on an object.
So here is my example.
If I try to run this program as it is then it doesn't display anything on the screen but if I comment out d->call() then it displays.
So here is my example.
C++:
#include <iostream>
class A {
virtual void call() = 0;
};
class B : public A {
public :
void call(){
std::cout << "This is class B" << std::endl;
}
};
class C : public A {
public :
void call(){
std::cout << "This is class C" << std::endl;
}
};
int main(){
B b;
C c;
C* d;
b.call();
c.call();
d->call()
return 0;
}
If I try to run this program as it is then it doesn't display anything on the screen but if I comment out d->call() then it displays.
Code:
This is class B
This is class C