Problem placing classes in separate files

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
mooska
Posts: 3
Joined: February 15th, 2012, 12:09 am

Problem placing classes in separate files

Post by mooska » February 20th, 2012, 8:02 am

I don't know if this is a suitable topic here, BUUUUUT I can't get this to work and I thought someone here might be able to shine some light on why I'm failing.

Character.h

Code: Select all

#ifndef CHARACTER_H
#define CHARACTER_H

class character
{
    public:
        character(string z, int a, int b, int c);
        void setClass(string x);
        void setHealth(int h);
        void setStr(int s);
        void setDex(int d);
        string getClass()
        {
            return pClass;
        }
        int getHealth()
        {
            return health;
        }
        int getStr()
        {
            return str;
        }
        int getDex()
        {
            return dex;
        }
    private:
        string pClass;
        int health;
        int str;
        int dex;

};

#endif // CHARACTER_H
Character.cpp

Code: Select all

#include <iostream>
#include <string>
#include "Character.h"

using namespace std;


character::character(string z, int a, int b, int c)
{
    setClass(z);
    setHealth(a);
    setStr(b);
    setDex(c);
}
void character::setClass(string x)
{
    pClass = x;
}
void character::setHealth(int h)
{
    health = h;
}
void character::setStr(int s)
{
    str = s;
}
void character::setDex(int d)
{
    dex = d;
}
How I fucked it up(Errors)

Code: Select all

Character.h|7|error: expected ')' before 'z'|
Character.h|8|error: 'string' has not been declared|
Character.h|12|error: 'string' does not name a type|
Character.h|29|error: 'string' does not name a type|
main.cpp|8|error: redefinition of 'class Character'|
Character.h|5|error: previous definition of 'class Character'|
main.cpp||In function 'int main()':|
main.cpp|61|error: no matching function for call to 'Character::Character(const char [8], int, int, int)'|
C:\Users\Mooska\Desktop\C++ Practice\Sabra\Character.h|5|note: candidates are: Character::Character()|
Character.h|5|note:                              Character::Character(const Character&)|
main.cpp|62|error: 'class Character' has no member named 'getClass'|
||=== Build finished: 8 errors, 0 warnings ===|

mooska
Posts: 3
Joined: February 15th, 2012, 12:09 am

Re: Problem placing classes in separate files

Post by mooska » February 20th, 2012, 10:45 am

Already figured out I need std:: in front of my strings in the header folder. Sorry for the post.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Problem placing classes in separate files

Post by chili » February 20th, 2012, 12:31 pm

No worries bro, glad you could figure it out on your own. :)
Chili

Post Reply