nested classes

This is a discussion on nested classes within the C++ Programming forums, part of the General Programming Boards category; Can I declare a nested class but define afterwords? Code: class a { public: class b; }; class a::b { ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    113

    nested classes

    Can I declare a nested class but define afterwords?
    Code:
    class a
    {
    public:
    class b;
    };
    
    class a::b
    {
    };
    I am getting error on doing this. Please suggest a way out if we can do this.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    It is possible and part of the typical PIMPL pattern implementation.

    What error do you get?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    its legal but some compilers dont like it.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    error reads
    Code:
    multiple declaration of a::b
    i am compiling it on turbo c++

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    sorry, i am not able to find it on faq

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    What version of Turbo C++?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    I am using turbo c/c++ 3.0

  8. #8
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    error reads

    Code:
    multiple declaration of a::b

    i am compiling it on turbo c++3.0

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    That's a horribly outdated compiler, known not to support any kind of nested classes.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone with a spare java class file(s) with nested classes?
    By Sebastiani in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-29-2009, 08:33 PM
  2. Problem with nested classes
    By Bargi in forum C++ Programming
    Replies: 5
    Last Post: 05-29-2008, 05:52 AM
  3. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  4. Nested Classes
    By manofsteel972 in forum C++ Programming
    Replies: 4
    Last Post: 11-21-2004, 10:57 AM
  5. nested classes...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 12-09-2001, 03:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21