![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Msvc++ = No Polymorphism???
im LOST.... how can i take a base pointer and look into the object of a derived class... Thanks!
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
MS VC++ is a compiler, not a language. It does a creditable job with polymorphism, pretty much what you'd expect. Is there a particular piece of code you have in mind, and a particular failure mechanism?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 | |
|
Expert Programmer
|
Quote:
im not stupid bro. MSVC++ is the only compiler that gives me this error for one language.... example: class Base
{
public:
Base() {;}
virtual ~Base() {;}
virtual void show()
{
cout << "Test Base." << endl;
}
};
class Derived:Base
{
public:
Derived() {;}
virtual ~Derived() {;}
void show()
{
cout << "Test Derived." << endl;
}
};
int main()
{
Base B;
Derived D;
Base *P; //my base pointer
P=&B; //works
P->show(); //works
P=&D; //creates an error
P->show();
return 0;
}if i cannot do this. its not polymorphism!!!!
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
The reason for the error is that inheritence of classes is private by default in C++. If other compilers are accepting your code without complaint, then those compilers are broken.
Try changing the inheritence to class Derived: public Base
{
// etc
} |
|
|
|
|
|
#5 | |
|
Expert Programmer
|
Quote:
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
works great thanks a ton
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#7 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#8 | |
|
Expert Programmer
|
Quote:
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I'm not really a programmer, that was just a subset tool. I'm a retired 64-year old EE.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 |
|
Expert Programmer
|
EE = electronic engineer? i need to get a degree in that also... so that i can soder(sp) my programs to a bread board
![]()
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|