Of these two programs the second one works but the first one does not compile. How is that possible? The only difference is that in version two bar is a pointer and in version one it isnt.
Version one: (does not compile)
#include <iostream>
class Foo{
public:
void print(){
std::cout << "asdasd" << std::endl;
}
};
class Bar : public Foo{
};
int main(){
Bar bar();
bar.print();
}
And the second version:
#include <iostream>
class Foo{
public:
void print(){
std::cout << "asdasd" << std::endl;
}
};
class Bar : public Foo{
};
int main(){
Bar* bar = new Bar();
bar->print();
}