Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 21st, 2005, 11:19 AM   #1
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Old Nov 21st, 2005, 11:50 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Nov 21st, 2005, 12:35 PM   #3
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
Quote:
Originally Posted by DaWei
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?

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
Kilo is offline   Reply With Quote
Old Nov 21st, 2005, 12:42 PM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
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
}
grumpy is offline   Reply With Quote
Old Nov 21st, 2005, 12:45 PM   #5
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
Quote:
Originally Posted by grumpy
The reason for the error is that inheritence of classes is private by default in C++. Try changing the inheritence to
class Derived:  public Base
{
     // etc
}
that makes complete sense.... let me go ahead and try that and i will get back to you! 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
Kilo is offline   Reply With Quote
Old Nov 21st, 2005, 1:00 PM   #6
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Old Nov 21st, 2005, 1:32 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
im not stupid bro.
I'm not your bro. More likely your granddaddy. Sorry your compiler was broken, though.
__________________
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
DaWei is offline   Reply With Quote
Old Nov 21st, 2005, 6:45 PM   #8
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
Quote:
Originally Posted by DaWei
I'm not your bro. More likely your granddaddy. Sorry your compiler was broken, though.
you could be my granddaddy bro? It wasn't broken lol, its was my fault i completely forgot about specifying wether or not the base class was public or private... How long have you been programming man? My grandfather has been since back in the day and (he uses COBOL) when they wanted him to learn Delphi he quit lol!
__________________
"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
Kilo is offline   Reply With Quote
Old Nov 21st, 2005, 6:50 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Nov 21st, 2005, 8:49 PM   #10
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:50 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC