Class and Instance having same name

Discussion in 'C++' started by ibm@svpal.org, Apr 7, 2008.

  1. Guest

    Consider the following code snippet:

    ....
    class XXXX
    {
    public:
    XXXX()
    {
    cout << " XXXX Constructor " << endl;
    };

    int i;
    };


    class YYYY
    {
    public:
    YYYY()
    {
    cout << " YYYY Constructor " << endl;
    };

    int i;
    class XXXX XXXX; // compiles ( g++ )
    // XXXX XXXX; // does not compile
    };
    ....

    Note the declaration/definition of an instance XXXX of class XXXX in
    class YYYY.
    It is my contention ( and g++ seems to agree ) that such a construct
    ought to be in error.
    VIsual C++ and another as yet unknown compiler ( the problem occurs in
    some third party code ) seem to have no trouble with the commented out
    code ( XXXX XXXX; ).
    What I'm looking for is material to wrap around a blunt object which I
    may then
    use to correct the offending third party if the fact the situation is
    as I suspect.
    Thanx.

    IBM
    , Apr 7, 2008
    #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. Sridhar R
    Replies:
    14
    Views:
    1,382
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Feb 10, 2004
  2. syang8
    Replies:
    1
    Views:
    285
    benben
    Nov 1, 2006
  3. Rahul
    Replies:
    1
    Views:
    749
    raof01
    Apr 13, 2008
  4. Martin P. Hellwig
    Replies:
    1
    Views:
    367
    Martin P. Hellwig
    Mar 26, 2010
  5. Ralph Shnelvar

    Same name for class and instance method

    Ralph Shnelvar, Nov 22, 2009, in forum: Ruby
    Replies:
    1
    Views:
    87
    Robert Klemme
    Nov 22, 2009
Loading...

Share This Page