This site is no longer active and is available for archival purposes only. Registration and login is disabled.

General C++ OOP Problem


General C++ OOP Problem

Postby fzammetti » Mar 14, 2005 @ 6:40pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby Structure » Mar 14, 2005 @ 6:46pm

A float, A float, My kingdom for a float
User avatar
Structure
pm Member
 
Posts: 147
Joined: Sep 17, 2004 @ 8:28pm
Location: UK


Postby fzammetti » Mar 14, 2005 @ 6:58pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby dan.p » Mar 14, 2005 @ 8:10pm

dan.p
pm Member
 
Posts: 89
Joined: Jan 6, 2005 @ 6:49am


Postby fzammetti » Mar 14, 2005 @ 8:14pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby Structure » Mar 14, 2005 @ 8:18pm

A float, A float, My kingdom for a float
User avatar
Structure
pm Member
 
Posts: 147
Joined: Sep 17, 2004 @ 8:28pm
Location: UK


Postby fzammetti » Mar 14, 2005 @ 8:21pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby Structure » Mar 14, 2005 @ 8:57pm

As im here,

Yes its good coding practice for future extendibility, only leave it out if you have a good reason why a possible extended class should never override the functionality
A float, A float, My kingdom for a float
User avatar
Structure
pm Member
 
Posts: 147
Joined: Sep 17, 2004 @ 8:28pm
Location: UK


Postby fzammetti » Mar 14, 2005 @ 9:08pm

That's what I figured. Kind of frustrating sometimes... I'm quite familiar with OOP techniques, but C++ is just different enough sometimes from Java to make C++ confusing when I'm doing Java all day :) Thanks again!
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby fzammetti » Mar 14, 2005 @ 9:12pm

Oops, spoke to soon... I guess I don't fully understand the need for declaring the virtual method in the derived class (I understand the REASON for it, but not the NEED)...

If class A has a virtual method in it (defined with an empty method body), and class B extends A but does NOT implement that method, and then class C extends class B, wouldn't class C still be able to implement that method by virtue of it's parent class (B) extending class A?

It sounds like you guys are saying the inheritance of a virtual method ends with any class that doesn't implement it or define it as virtual itself, i.e., is lost to any derived classes after that down the hierarchy. Is that the case?
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby dan.p » Mar 14, 2005 @ 9:51pm

I've only been coding in C++ for three months, but there's one thing I've learned the hard way:

Always apply good coding practices when programming in C or C++, otherwise you're in for trouble later on. C/C++ does whatever you tell it, even if it's blatantly fubard code.

Examples:

FLOAT fX = 1.25;
DWORD dwX = (DWORD) fX;

This one caused me quite a few problems and took me a while to figure out

#define FunMacro(x) x / 2;

// Somewhere in your code..
FunMacro(5 + 233);

Yet one reason why macros should be avoided, because errors are so easy to make with them if they aren't properly handled

So many things can happen, it's endless. Be careful. ;)

As for your particular virtual fun, I do believe the class inherited from must have virtual in front of the function if you want polymorphism to take effect. If you don't define a function as virtual in one of the derived classes, then the buck stops there, and fun things begin to happen. :P
dan.p
pm Member
 
Posts: 89
Joined: Jan 6, 2005 @ 6:49am


Postby Structure » Mar 14, 2005 @ 10:29pm

A float, A float, My kingdom for a float
User avatar
Structure
pm Member
 
Posts: 147
Joined: Sep 17, 2004 @ 8:28pm
Location: UK


Postby fzammetti » Mar 14, 2005 @ 10:36pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby dan.p » Mar 14, 2005 @ 10:39pm

EDIT:
Quoted you wrong. Rephrasing what I said.

I don't find it silly to declare derived class functions virtual. If you think about it, by declaring a derived classes function virtual, you're saying "this function overrides the function in the derived class."

When programming you always want to be clear with what you're doing, even if it makes no difference if you left out a keyword or not. After all, we are dealing with a language, and you want to say what you're doing clearly. I'm reminded of a quote.. not sure exactly what it was, but something along the lines of "good code comments itself." I think that'd apply here.

Also, every compiler is different. Some compilers may treat virtual slightly different, and require it to be there. Although I find it unlikely, but you never know.
dan.p
pm Member
 
Posts: 89
Joined: Jan 6, 2005 @ 6:49am


Postby mlepage » Mar 14, 2005 @ 10:43pm

www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Next

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron