how would i declare it so it intializes to c1,t1,and r1;Code:int MAX = 3; int main (void) { cCIRCLE c1; cTRIANGLE t1; cRECTANGLE r1; cSHAPE arShape(); <---Error }
how would i declare it so it intializes to c1,t1,and r1;Code:int MAX = 3; int main (void) { cCIRCLE c1; cTRIANGLE t1; cRECTANGLE r1; cSHAPE arShape(); <---Error }
Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more
The best in Technology and Gaming News
www.back2games.com
c1, t1 and r1 are all objects....what is arShape()?? Is it a function???
simple is always an understatement.....
cSHAPE is a superclass
Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more
The best in Technology and Gaming News
www.back2games.com
Yeah...but what is arShape()
Last edited by sweets; 04-18-2004 at 01:39 PM.
simple is always an understatement.....
arSHAPE is a variable intialized by cSHAPE class; it is a pointer to character.
Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more
The best in Technology and Gaming News
www.back2games.com
> cSHAPE arShape(); <---Error
arShape is not a variable.... by putting ()'s you are saying its a function
simple is always an understatement.....
here is the whole code:
HEADER FILE:
CPP FILE:Code:#ifndef __CSHAPE_H #define __CSHAPE_H #include <string.h> #include <iostream.h> class cSHAPE { protected: //Member Variables char* ptrName; public: //Methods //Constructor cSHAPE(const char* ptr) { ptrName=NULL; if (ptr) { ptrName = new char[strlen(ptr)+1]; strcpy(ptrName,ptr); } } ~cSHAPE() { if (ptrName) delete[] ptrName; } const char* getName() { return(ptrName); } virtual void displayShape() = 0; virtual void eraseShape() = 0; }; class cCIRCLE:public cSHAPE { public: cCIRCLE():cSHAPE("Circle") {} void displayShape() { cout << "- " << ptrName << " has a radius "<< endl; } void eraseShape() { cout << "- " << "Erasing:" << ptrName << endl; } }; class cTRIANGLE:public cSHAPE { public: cTRIANGLE():cSHAPE("Triangle") {} void displayShape() { cout << "- " << ptrName << " can be located in Bermuda "<< endl; } void eraseShape() { cout << "- " << "Erasing:" << ptrName<< endl; } }; class cRECTANGLE:public cSHAPE { public: cRECTANGLE():cSHAPE("Rectangle") {} void displayShape() { cout << "- " << ptrName << " may be a square if all sides are equal "<< endl; } void eraseShape() { cout << "- " << "Erasing:" << ptrName<< endl; } }; #endif
Code:#include "cshape.h" #include <iostream.h> const int MAX = 3; void main (void) { cCIRCLE c1; cTRIANGLE t1; cRECTANGLE r1; char szStr1[] = "cir"; char szStr2[] = "tri"; char szStr3[] = "rec"; cSHAPE arShape(????); }
Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more
The best in Technology and Gaming News
www.back2games.com
ok i have declared arShape
now how would i assign arShape[1] to c1, [2] to t1, and [3] to r1Code:cSHAPE* arShape[MAX];
Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more
The best in Technology and Gaming News
www.back2games.com
if the cShape constructor is defined as: cSHAPE(const char* ptr) {...}
wouldn't you have to change cSHAPE arShape(????); to cSHAPE arShape("const char pointer"); ?
where MAX is a const intCode:cSHAPE *arShape[MAX]
initalizes three pointers to cSHAPE object, now i am trying to assign each pointer to each shape (ie: arShape[0] to circle, arShape[1] to triangle and arShape[2] to rectangle)
Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more
The best in Technology and Gaming News
www.back2games.com
k i got it
now i am trying to call a virtual function in my header file:Code:arShape = &c1 . . .
CPP FILECode:void doNonVirtual() { cout << "- I am the doNonVirtual of the base class" << endl; }
but i am getting a syntax error when i call the virtual functionCode:for (int i=0;i < MAX ; i++) { cout << " Object is a " << arShape[i]->getName() << endl; cout << "calling doNonVirtual Function" << arShape[i].doNonVirtual(); } system("PAUSE"); }
Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more
The best in Technology and Gaming News
www.back2games.com
Which virtual function would that be? I don't see any in that code.but i am getting a syntax error when i call the virtual function
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials