Thread: C2061 error in header file

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    13

    C2061 error in header file

    In the code (.h file)below, I am creating a class clsA with a constructor.
    Then, I am declaring another class clsB, which always will have 2 instances of clsA.
    I am getting the C2061 error

    c:\vcppnet\new\new\stdafx.h(19) : error C2061: syntax error : identifier 'TYPE1'
    c:\vcppnet\new\new\stdafx.h(20) : error C2061: syntax error : identifier 'TYPE1'

    Can I get some help in resolving this please?

    Code:
    typedef enum {TYPE1, TYPE2} enumType;
    class clsA{
    	public:
    		int a;
    		clsA(enumType n_type){a=n_type;};
    };
    
    class clsB{
    public:
    	clsA A1(TYPE1);
    	clsA A2(TYPE2);
    };

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    unless you are going to have A1 and A2 as static members, you must initialise them in the clsB constructor.

    either
    Code:
    typedef enum {TYPE1, TYPE2} enumType;
    
    class clsA{
    	public:
    		int a;
    		clsA(enumType n_type){a=n_type;};
    };
    
    class clsB{
    public:
        clsA A1;
        clsA A2;
        clsB() : A1(TYPE1), A2(TYPE2) {}
    };
    or...
    Code:
    typedef enum {TYPE1, TYPE2} enumType;
    
    class clsA{
    	public:
    		int a;
    		clsA(enumType n_type){a=n_type;};
    };
    
    class clsB{
    public:
        static clsA A1;
        static clsA A2;
    };
    
    clsA clsB::A1(TYPE1);
    clsA clsB::A2(TYPE2);

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    13
    Thanks Bench32 ; the first solution will work for me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Replies: 6
    Last Post: 04-02-2002, 05:46 AM