C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-09-2009, 11:03 AM   #16
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Quote:
Originally Posted by Tux0r View Post
When the values of them are the same then the destructor is called. The destructor will call an event. Like, creating a chest with treasure because the enemies were defeated. I believe it makes perfect sense, and because I'm using polymorphism I have to new (afaik).
You do not have to use new to use polymorphism.
All you need is a pointer or reference to the base class. Thus this will work:
Code:
Derived a;
Base* pa = &a;
pa->myfunction();
// Or
Base& ra = a;
ra.myfunction();
Furthermore, using delete this is something I would not recommend.
If you don't want to do manual deleting, then use smart pointers.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.

Last edited by Elysia; 07-09-2009 at 12:37 PM.
Elysia is offline   Reply With Quote
Old 07-09-2009, 11:26 AM   #17
Registered User
 
Join Date: Apr 2006
Location: United States
Posts: 3,201
Well that's a crap way to demonstrate polymorphism, since that's not polymorphic at all.

Imagine two classes to represent the time, TwelveHourClock and TwentyFourHourClock, related through the abstract data type Time, which at minimum specifies for its children a timestamp method. One way to dump the time for all the Time types is through a polymorphic function.
Code:
void print (std::ostream& os, const Time& now) {
   os << "The time is " << now.timestamp() << '\n';
}
__________________
Os iusti meditabitur sapientiam
Et lingua eius loquetur indicium

"There is nothing either good or bad, but thinking makes it so." (Shakespeare, Hamlet, Act II scene ii)

http://www.myspace.com/whiteflags99
whiteflags is offline   Reply With Quote
Old 07-09-2009, 11:56 AM   #18
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Quote:
Originally Posted by whiteflags View Post
Well that's a crap way to demonstrate polymorphism, since that's not polymorphic at all.
It was a way to demonstrate that you don't have to use new to use polymorphism.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 07-09-2009, 12:36 PM   #19
Registered User
 
Join Date: Apr 2006
Location: United States
Posts: 3,201
But you didn't use polymorphism, so sorry if it's really my fault that you demonstrated so little.
__________________
Os iusti meditabitur sapientiam
Et lingua eius loquetur indicium

"There is nothing either good or bad, but thinking makes it so." (Shakespeare, Hamlet, Act II scene ii)

http://www.myspace.com/whiteflags99
whiteflags is offline   Reply With Quote
Old 07-09-2009, 12:38 PM   #20
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Alright, perhaps it was a bad example. I realize that now... I used a single class.
Well, I edited it to use Derived and Base to demonstrate that we're talking about polymorphism.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 07-09-2009, 05:00 PM   #21
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,470
Quote:
It will break broken usages of the facade pattern. There is nothing in the facade pattern that requires the facade to be a friend. Specifically, the facade pattern is not intended as a means of circumventing access control.
I was not indicating this was the case.
__________________
If you aim at everything you will hit something but you won't know what it is.
Bubba is offline   Reply With Quote
Reply

Tags
class, namespace

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
question about a working linked list cold_dog C++ Programming 23 09-13-2006 01:00 AM
data validation & namespace tiange C++ Programming 4 07-05-2005 02:45 AM
Templated Binary Tree... dear god... Nakeerb C++ Programming 15 01-17-2003 02:24 AM
can't insert data into my B-Tree class structure daluu C++ Programming 0 12-05-2002 06:03 PM
Post programs GaPe C# Programming 8 05-12-2002 11:07 AM


All times are GMT -6. The time now is 02:48 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22