Re: compilation error

Discussion in 'C++' started by Rolf Magnus, Jun 27, 2003.

  1. Rolf Magnus

    Rolf Magnus Guest

    Jan Engelhardt wrote:

    > /*
    > Hi,
    >
    >
    > if the following program is compiled with g++, an error is issued:
    > dumb.cpp: In function `int main()':
    > dumb.cpp:9: error: cannot convert `linked_list::linked_obj*' to
    > `linked_obj*'
    > in initialization
    >
    > however, TCPP (Turbo C++ DOS 16bit) did not complain.
    > It looks like g++ just "kills" the keyword struct (and
    > makes it a class), which is not what I want.
    > Is this a g++ bug, or g++'s intention?


    It's intention, since there is (except from the default access rights)
    no difference between a struct and a class in C++. You seem to assume
    something else.

    > If it is intention, how can it be circumvented?


    Use another language than C++. Btw: why do you think that language
    designer's and compiler writer's intentions always have to be
    circumvented? You should first be asking yourself what you are doing
    wrong, not how to circumvent language features.

    > I am using "g++ (GCC) 3.3 20030226 (prerelease) (SuSE Linux)"
    >
    >
    > - Jan Engelhardt
    >
    > */
    > struct linked_list {
    > struct linked_obj { int n; } obj;
    > };
    > class NiceClass { public: struct linked_list *arg; };
    >
    > int main(void) {
    > NiceClass sth;
    > sth.arg = new struct linked_list;
    > struct linked_obj *p = &sth.arg->obj;


    The above two uses of the struct keyword are superfluous. You can leave
    them out. But that's not the problem. The problem is that the
    linked_obj that is defined above is nested withing linked_list. So you
    have to write:

    linked_list::linked_obj *p = &sth.arg->obj;

    > return 1;
    > }
    >
    Rolf Magnus, Jun 27, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vittal
    Replies:
    2
    Views:
    701
    Gordon Burditt
    Jul 8, 2003
  2. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,291
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  3. Gavin
    Replies:
    3
    Views:
    467
    Chris Uppal
    Mar 28, 2007
  4. C__chp
    Replies:
    4
    Views:
    501
    Puppet_Sock
    Feb 15, 2008
  5. Tassador

    const string error compilation - error C2679

    Tassador, Jul 19, 2009, in forum: C Programming
    Replies:
    0
    Views:
    622
    Tassador
    Jul 19, 2009
Loading...

Share This Page