why dont this work?!

Started by
8 comments, last by EvilCrap 22 years, 3 months ago
im trying to do this thing with virtual functions and stuff. where CDog and CCat have base class CAnimal, and private virutal Act() in common: CCat Cat; CDog Dog; CAnimal **Animal = NULL; Animal = new CAnimal*[2]; Animal[0] = &Dog Animal[1] = &Cat Animal[0].Act();//err Animal[1].Act();//err when i call .Act(), i get this compiler error: //error C2228: left of ''.Act'' must have class/struct/union type How can i call these, or am i doing this entire thing wrongly?
Advertisement
"private virutal Act()"

Maybe cause it''s private.....
and when you derive classes they don''t appear....


jeez


Pac
-Pac "The thing I like about friends in my classes is that they can't access my private members directly." "When listening to some one tell about their problem (whether it's code or not), don't listen to what went right or wrong, but what they assumed....."
jeez?~!?!?!

you SAY jeez?!!?!?!?

well, mr (knowetall), i happened to have figured it out...

and it should be ->Act();

DUHHHH!!! MVC++ is so dumb, i swear, you think it could spot that.

i swear i cant beleive i wasted so much brain power on dat mistype.
hmm sorry maybe my original post wasnt clear
...
where CDog, and CCat, have Base Class CAnimal and private virtual Act() in common.
...
??
hmm sorry maybe my original post wasnt clear
...
where CDog, and CCat, have Base Class CAnimal and private virtual Act() in common.
...
??
I could answer the question.

But it wouldn''t be helpful to do so.

Your compiler ships with documentation, including semi-detailed explanations of the error messages it produces.

Learn how to use them. It will serve you well.

char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
HeHe,

Gotta love it when people think that a $1,600 program is stupid!

/*
======================
Pop me an email
Here

"In Windows, the only thing opposing safe mode would be... Unsafe mode....??"
- Me

"hmm, I know the slogans "will work for food" and "will work for free", but "will pay for work I do" seems just a bit sick "
- MirekCz

"I want to do this huge ass multiplayer first person space sim rpg strategy game!!"
======================
*/

"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I'm reaching up and reaching out. I'm reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one's been. We'll ride the spiral to the end and may just go where no one's been." - Maynard James Keenan Name: [email=darkswordtbj@hotmail.com]TheBlackJester[/email]Team: Wildfire Games
Projects O A.D.The Last Alliance

Animal[0] and Animal[1] are pointers, so you have to use the -> operator to access the methods.

CCat Cat;
CDog Dog;
CAnimal **Animal = NULL;
Animal = new CAnimal*[2];
Animal[0] = &Dog
Animal[1] = &Cat

Animal[0]->Act(); // should work now
Animal[1]->Act(); // should work now



No, HTML is not an OO language.
VC in fact did spot that. What do you think that error message means?



-Brannon
-Brannon
yes, i know,

but, it should say at what level ur pointers are messed up at!
!!

This topic is closed to new replies.

Advertisement