Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3046

question about polymorphism in c++

$
0
0
Hello, im starting out in c++ and i want to know why this code prints out base

Code:

struct base
{
    virtual void foo(void){
        cout<<"base"<<endl;
    }
 }
 struct derived : base(void)
 {
  void foo(void){
      cout<<"derived"<<endl;
  }
 }
 
int main (void)
 {
 base *b = new derived;
 b -> foo();
 return 0
 }

i know that when making a program like this in java the output would be derived.. I would like to know how it works in c++. thank you for your time

Viewing all articles
Browse latest Browse all 3046

Trending Articles