This don't look right

This is a discussion on This don't look right within the C++ Programming forums, part of the General Programming Boards category; Is this a legal statment in C/C++? (look at the struct please) Code: // Player.h: interface for the CPlayer class. ...

  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,267
    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

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