home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!usenet.coe.montana.edu!rpi!masscomp!macdonal
- From: macdonal@westford.ccur.com (Steve MacDonald)
- Newsgroups: comp.lang.c++
- Subject: Turbo C++ vs. Gnu C++
- Message-ID: <1992Aug25.165224.27556@westford.ccur.com>
- Date: 25 Aug 92 16:52:24 GMT
- Article-I.D.: westford.1992Aug25.165224.27556
- Sender: usenet@westford.ccur.com (UNIX news)
- Distribution: usa
- Organization: Concurrent Computer Corp. Westford, MA
- Lines: 100
-
- I have a question regarding the following code. This compiles fine with the
- Gnu C++ compiler, but when I compile this on the latest version of Turbo C++
- on a p.c., I get an error. I'll flag the line to the right of where it appears.
-
- #include <stream.h>
- #include <string.h>
- #include <new.h>
- #define endl "\n"
-
- //Example3_8
- int classcount; //Accessing an array of class pointers.
-
- class Test{
- public:
- Test() {
- print(word = "NO INITIALIZER SUPPLIED");
- count = ++classcount;
- }
-
- Test(char *mess ="HELLO")
- {
- print(word = mess);
- count = ++classcount;
- }
-
- Test(char *mess1, char *mess2){
- print(word = mess2);
- count = ++classcount;
- }
-
- Test(Test &clone){
- print("I'm a clone class");
- count = ++classcount;
- word = clone.word;
- }
-
- ~Test() {
- print ("GoodBye");
- classcount--;
- }
-
- void print(char *mess){
- cout<<mess<<endl;
- }
-
- void print() {
- cout<<word<<endl;
- }
-
- int getcount(void){
- return count;
- }
-
- protected:
- char *word;
- int count;
- };
-
- main(){
-
- Test *classptrarray[10];
-
- for(int i = 0; i < 10; i++)
- classptrarray[i] = new Test; ***TURBO C++ yields the following error
- message:
- Error c:\tc\examples.cpp 58: Ambiguity
- between 'Test::Test()' and 'Test::
- Test(char near*)' in function main()
-
- int a;
- for(int x = 0; x < 10; x++){
- a = classptrarray[x] -> getcount();
-
- //a = (*(classptrarray + x)) -> getcount();
- //Alternate pointer syntax
-
- cout<<a<<endl;
- }
-
- //delete [10] classptrarray;
- //Generates a runtime error: "null pointer assignment"
- //new "mem" for 10 classes not deleted.
-
- //delete classptrarray;
- //Same error as above and "new" mem not deleted
-
- //This is the correct way to delete
- for(i = 0; i < 10; i++){
- a = classptrarray[i] -> getcount();
- delete classptrarray[i];
- cout<<a<<endl;
- }
- }
-
-
- Again, when I compile and run this in the Gnu environment, no problems. What is
- wrong with this picture?
-
- Regards,
- Steve
-