The Daily Click ::. Forums ::. Non-Klik Coding Help ::. C++ Classes Help
 

Post Reply  Post Oekaki 
 

Posted By Message

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
23rd January, 2005 at 06:53:17 -

Dudes. The day we was taught about resolving ambiguity in classes during inheritance (to increase the polymorphism, the single interface many methods jazz) i had about 2 and a half hours sleep, so the lights was barely on but nobody was in and i have practical test coming up relatively soon.

heres some rubbish code to show what i mean :

#include <iostream>

#include <string>
using namespace std;

class baseclass

{
private:

int biscuits ;
float stuff ;
string blah ;

public:
void setbiscuits();


void setstuff( float sttemp )

{
stuff = sttemp ;
}

baseclass() ;
~baseclass() ;

void print_stuff ( void )

{
cout << "You have " << stuff << " stuff" << endl ;
}

} ;

baseclass::baseclass()

{
biscuits = 5 ;
stuff = 3.2345 ;
blah = "Bugger" ;
cout << "Base Class Created" << endl ;
}

baseclass::~baseclass()

{
cout << "Bugggggggggger Bye!" << endl ;
}

class fryup : public baseclass

{
private:
float chips ;

public:
fryup() ;
~fryup() ;
void setstuff( float fries )
{
chips = fries ;
}

void print_chips ( void )
{
cout << "There is " << chips << " chips" << endl ;
}
} ;

fryup::fryup()

{
cout << "Fryup Class Created" << endl ;
}

fryup::~fryup()

{
cout << "Bugggggggggger Bye!" << endl ;
}

int main(void)
{

fryup mydinner ;

mydinner.setstuff( 500.563 ) ;
mydinner.print_chips();
mydinner.print_stuff();

system("PAUSE");
return 0;
}


how do i stop this ambiguity problem? Any help will be greatly appreciated . I remember somthing about the virtual keyword but thats about it.

 
n/a

Tigerworks

Klik Legend

Registered
  15/01/2002
Points
  3882
23rd January, 2005 at 12:34:26 -

What ambuguity problem? Is there a specific line which gives an error?

 
- Tigerworks

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
23rd January, 2005 at 13:36:36 -

The method "setstuff" is present in both classes so it does not work properly but borland compilers give a error . The class of "fryup" is inheriting from the class of "baseclass"

Image Edited by the Author.

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
23rd January, 2005 at 13:51:43 -

Sounds like a job for a virtual function.

I'm crap with them so you're best checking here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/deriv_13.asp

... or here...

http://www.google.co.uk/search?hl=en&q=virtual+functions&btnG=Google+Search&meta=

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
23rd January, 2005 at 20:21:54 -

im crap at c++ so i can't help, sorry. Yeah i dunno why i posted to say that.

 
.

DaVince

This fool just HAD to have a custom rating

Registered
  04/09/2004
Points
  7998

Game of the Week WinnerClickzine StaffHas Donated, Thank You!Cardboard BoxDos Rules!
24th January, 2005 at 05:56:43 -

Why doesn't Clickteam create a click product with which you can create extensions for TGF, MMF, MMF2?

 
Old member (~2004-2007).

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
24th January, 2005 at 11:06:27 -

they'd probably be too slow. C[++] all the way!

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
24th January, 2005 at 11:48:26 -

Yes its pronounced "see plus plus" and thanks for the help everyone .

Plus if you want boat loads of speed use Assembly language, but then it will only work on your computer .

 
n/a

ChrisB

Crazy?

Registered
  16/08/2002
Points
  5457
24th January, 2005 at 11:54:26 -

As long as you restrict yourself to the x86 instruction set you'll be fine. What do you think compilers do anyway?

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
24th January, 2005 at 12:22:14 -

well, you could compile the same C++ program on 10 different processors, but not assembly... unless of course they all used the same keywords

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
24th January, 2005 at 14:19:16 -

Kris thats what i understood, in assembly (well i program a 8088 microcontroller [which is an 8 bit data bus version of the 8086 ] in assembly ) you have to put the memory adress say "mov 0092,AX" move the accumalator contents to mem adress 0x0092. So therefore if the persons computer is using that memory your program will do bugger all. Also if you start doing fancy hardware calls to say a IDE controller its all hardware specific.

Theoretically i could make a program in assembly to work with my GeForce graphics card (3d and stuff), but it would only work with that very chipset and brand.

Oh and a a true compiler translates to machine code and links (if you need it to), a lot of new fangly languages are just interpreters .

 
n/a

turboferret



Registered
  04/07/2004
Points
  2
31st January, 2005 at 13:19:36 -

define your baseclass like this:

class baseclass

{
private:

int biscuits ;
float stuff ;
string blah ;

public:
virtual void setbiscuits();


virtual void setstuff( float sttemp )

{
stuff = sttemp ;
}

baseclass() ;
~baseclass() ;

virtual void print_stuff ( void )

{
cout << "You have " << stuff << " stuff" << endl ;
}

} ;

when you inherit from this class, and the new class contains a method that is defined as virtual in the baseclass the baseclass's method will be overridden with the inheriters.

 
This monkey is useless, it only has ONE ass!!!

RC



Registered
  17/02/2004
Points
  141
22nd February, 2005 at 03:03:36 -

Yeah.. you have to use the Standard(forgot the name of what they call the standard ).. anyway. I've been teaching myself C++ for the past month and wow I actually understood that :]

 
http://www.sepwich.com/solemnity/projects/s4comingsoon.JPG
Sonic: Corrupted Chaos. Coming soon..
   

Post Reply



 



Advertisement

Worth A Click