Thread: Character type conversion error

  1. #1
    Registered User
    Join Date
    Mar 2006

    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.
    class player{
        LOCATION currentLocation;
        STATUS currentStatus;
        WEAPONS currentWeapon;
        BADGES currentBadge;
        int currentHitPoints, maxHitPoints, speed, dexterity, intelligence,
            numOfKills, numOfTimesKilled;
        char name[];
        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
    char* getName() { return name; }

    And remove the extraneous ";" when defining the functions inline
    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
    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, 02: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, 04:49 AM