[comp.lang.c++] Is a struct a class?

pcb@usl.usl.edu (Peter C. Bahrs) (10/08/88)

From the readings, I was under the impression that a struct in C++
is a class.

So given:

class {
  struct X {
         int a; int b;
           } * X;
// and some more stuff
}

The statement:
        X = new X;
bombs in AT&T C++ on 3B2/Sys V.  Any comments?
Thanks in advance.

henry@utzoo.uucp (Henry Spencer) (10/10/88)

In article <449@usl.usl.edu> pcb@usl.usl.edu (Peter C. Bahrs) writes:
>From the readings, I was under the impression that a struct in C++
>is a class.

Yes.

>        X = new X;
>bombs in AT&T C++ on 3B2/Sys V.  Any comments?

Did you declare the variable X before using it?  With the proper type,
which is "X *" (since "new X" returns pointer-to-X)?  What you have
written is an assignment statement, not a declaration.  Also, note that
one major difference between C++ and C is that a class declaration in
C++ implicitly does a typedef as well, which means using the same name
for a variable and a type is a bad idea.  Try making it "X *Y = new X;".
-- 
The meek can have the Earth;    |    Henry Spencer at U of Toronto Zoology
the rest of us have other plans.|uunet!attcan!utzoo!henry henry@zoo.toronto.edu