+ Reply to Thread
Results 1 to 2 of 2

Thread: What is anonymous class in C++?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    27

    What is anonymous class in C++?

    What is anonymous class in C++?

    How to use them? Give me some example.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    24
    Anonymous class is a class which has no name given to it.

    It is helpful when you use 'typedef' as described in below case:

    Code:
    typedef class
    {
    public:
    	int m_nRoleID ;
    	//Student() {} ;//this would create a warning C4183!
    } Student ;
    
    void PassAnonymousClassAsArgument(Student objStudent)
    {
    }
    
    void UseAnonymousClass()
    {
    	Student objStudent ;
    	objStudent.m_nRoleID = 1 ;
    	int nRoleID = objStudent.m_nRoleID ;
    }
    Note:
    Please note that anonymous class cannot have constructor or destructor!
    Last edited by Victoria; 06-22-2012 at 11:30 PM.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts