home *** CD-ROM | disk | FTP | other *** search
- /* CRAIGTAT.CPP:
-
- When declaring an instance of a class with the intention of
- invoking the default constructor the syntax is:
-
- MyClass Object; not MyClass Object();
- */
-
- #include <iostream.h>
- #include <string.h>
-
- class MyClass {
- char *myString;
- public:
- MyClass( char* dfault="default string") {
- myString = strdup( dfault );
- }
- ~MyClass(){ delete myString; };
- void Display(){ cout<<myString<<endl;};
- };
-
- //*******************************************************************
- int main(void)
- {
- MyClass Obj1; // default constructor is called
-
- /* Here we are NOT invoking the constructor that takes no
- arguments instead we are declaring a function 'Obj2' that
- takes no arguments and returns an object of type 'MyCass'.
- We will get no error message here---only later when we try
- to use it as a class. */
- MyClass Obj2();
-
- Obj1.Display(); // Works like a champ!
-
- // "Error:Left side must be a structure in function main()"
- Obj2.Display();
-
- return 0;
- } // end of main()
-