Character type conversion error

This is a discussion on Character type conversion error within the C++ Programming forums, part of the General Programming Boards category; I'm laying out a framework for a game project that I'm interested in making. I have a generic class to ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Ohio
    Posts
    37

    Question Character type conversion error

    I'm laying out a framework for a game project that I'm interested in making. I have a generic class to handle each different type of object that will be in the game. Inside each class is a member called name which is a character array 8 elements long. Now since the name member is private, I have a member method called getName which is a method of a character type which simply returns the array held by the name member. I'll post the class in question as it's easier to see all of it.
    Code:
    class player{
    private:
        LOCATION currentLocation;
        STATUS currentStatus;
        WEAPONS currentWeapon;
        BADGES currentBadge;
        int currentHitPoints, maxHitPoints, speed, dexterity, intelligence,
            numOfKills, numOfTimesKilled;
        char name[];
    public:
        player();
        int getCurHP(){return currentHitPoints;};
        int getMaxHP(){return maxHitPoints;};
        int getSpeed(){return speed;};
        int getDexterity(){return dexterity;};
        int getIntelligence(){return intelligence;};
        int getNumOfKills(){return numOfKills;};
        int getNumOfTimesKilled(){return numOfTimesKilled;};
        char getName(){return name;};
        LOCATION getCurLoc(){return currentLocation;};
        STATUS getCurStatus(){return currentStatus;};
        WEAPONS getCurWeapon(){return currentWeapon;};
        BADGES getCurBadge(){return currentBadge;};
        void incCurHP(int inc);
        void decCurHP(int dec);
        void incMaxHP(int inc);
        void decMaxHp(int dec);
        void incSpd(int inc);
        void decSpd(int dec);
        void incDex(int inc);
        void decDex(int dec);
        void incInt(int inc);
        void decInt(int dec);
        void incNumOfKills(int inc){numOfKills += inc;};
        void incNumOfTimesKilled(int inc){numOfTimesKilled += inc;};
        void setCurLoc(LOCATION newLoc);
        void setCurStatus(STATUS newStatus);
        void setCurWeapon(WEAPONS newWeapon);
        void setCurBadge(BADGES newBadge);
        void setName(char newName[]);
    };
    LOCATION, WEAPONS, STATUS, and BADGES are enumerations, just for clarification. Anyway, the line that contains the member method prototype for getName is the line that the compiler complains about. It says it's an invalid conversion from char* to char. It might be something small but I'm not picking up what it is I should be doing to fix this. Any ideas?? Thanks in advance.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,404
    char* getName() { return name; }

    And remove the extraneous ";" when defining the functions inline
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Use the C++ string class instead of C style strings, then return the string like you would an int or enum.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM

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