Thread: This don't look right

  1. #1
    Registered User OxYgEn-22's Avatar
    Join Date
    Apr 2002
    Posts
    36

    Question This don't look right

    Is this a legal statment in C/C++? (look at the struct please)

    Code:
    // Player.h: interface for the CPlayer class.
    //
    
    #ifndef _PLAYER_H_
    #define _PLAYER_H_
    
    class CPlayer : public CBasePlayer  
    {
    public:
    	CPlayer();
    	virtual ~CPlayer();
    
    	void Inventory();
    	int FirstWep();
    	int SeconWep();
    
    private:
    
    	struct s_iInvent
    	{
    		char name[30];
    		int type;
    		int ammt;
    	};
    
    	s_iInvent[18];
    };
    
    #endif // _PLAYER_H_
    Is that air you're breathing?

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    nope

    use

    Code:
            struct s_iInvent
    	{
    		char name[30];
    		int type;
    		int ammt;
    	};
    
    	struct s_iInvent varname[18];
    or

    Code:
            typedef struct 
    	{
    		char name[30];
    		int type;
    		int ammt;
    	}s_iInvent;
    
    	s_iInvent  varname[18];
    or

    Code:
            struct s_iInvent
    	{
    		char name[30];
    		int type;
    		int ammt;
    	}varname[18];
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    one more

    This is the official way to do it, see latest ANSI C++ specification

    (in C++, in C it's wrong)

    Code:
    ...
    s_iInvent varname[18];

  4. #4
    Registered User OxYgEn-22's Avatar
    Join Date
    Apr 2002
    Posts
    36
    oh!, thanks. My monitor must be broken.. hehe, thanks guys for the help!!
    Is that air you're breathing?

Popular pages Recent additions subscribe to a feed