class question

This is a discussion on class question within the C++ Programming forums, part of the General Programming Boards category; Hello.. Could someone explain me this: Code: class someclass_1 { public: class someclass_2; friend class someclass_2; ... }; class someclass_1::someclass_2 ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    class question

    Hello..

    Could someone explain me this:

    Code:
    class someclass_1 {
    public:
    	class someclass_2;
    	friend class someclass_2;
    	
    	...
    
    };
    
    class someclass_1::someclass_2 {
    public:
    	friend someclass_1;
    
    	...
    };

    Thanks a lot for help

  2. #2
    Registered User zouyu1983's Avatar
    Join Date
    Nov 2006
    Location
    Fuzhou University, Fujian, China
    Posts
    35
    if you want to make the class someclass_2 the friend class of the someclass_1, you must declare it first, otherwise the compiler will not know what the someclass_2 is.

    but in someclass_2, you can just write the friend someclass_1 because the compiler knows what the someclass_1 which you have defined or declared looks like.
    Last edited by zouyu1983; 12-01-2006 at 10:17 AM.

  3. #3
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    But why this:

    Code:
    class someclass_1::someclass_2

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    because of this
    Code:
    class someclass_1 {
    public:
    	class someclass_2;
    someclass_2 is a member of the someclass_1
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User zouyu1983's Avatar
    Join Date
    Nov 2006
    Location
    Fuzhou University, Fujian, China
    Posts
    35

    Wink

    Quote Originally Posted by l2u
    But why this:

    Code:
    class someclass_1::someclass_2
    Oh, sorry, i didn't see it clearly.

    the someclass_2 is a member of the smoeclass_1 because you declare it in the someclass_1, so when you define the someclass_2,you must write it like the style you posted.
    Hello, guys, i come from china, so i am not good at english. If you find the sentence i wrote full of mistakes, please tell me.
    I confirm that my english and programming skills will be improved with your help in this forum. thanks^_^

  6. #6
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    So someclass_2 is declared only for someclass_1 ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  2. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 05:08 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

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