home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turbo Toolbox
/
Turbo_Toolbox.iso
/
dtx9202
/
borhot
/
craigtat.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-06
|
2KB
|
59 lines
/* ------------------------------------------------------ */
/* CRAIGSTAT.CPP */
/* (c) 1990 Borland International */
/* All rights reserved. */
/* ------------------------------------------------------ */
/* veröffentlicht in: DOS toolbox 2'92 */
/* ------------------------------------------------------ */
/*
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()
/* ------------------------------------------------------ */
/* Ende von CRAIGTAT.CPP */