Hello elliotawerstedt,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can us the preview button at the bottom to see how it looks.
The first part that jumps out at me is your class. A little better way to write the class is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
class Person
{
public:
Person();
~Person();
void Set(std::string namn, int alder);
std::string GetNamn();
int Getalder();
void SkrivUt();
private:
std::string m_namn;
int m_alder;
};
Person::Person()
{
}
Person::~Person()
{
}
void Person::Set(std::string namn, int alder)
{
m_namn = namn;
m_alder = alder;
}
std::string Person::GetNamn() { return m_namn; }
int Person::Getalder() { return m_alder; }
void Person::SkrivUt()
{
cout << m_namn << endl;
cout << m_alder << endl;
}
|
You have your variables as "public" which defeats the the purpose of the class. They should be "private".
When describing the problem you talk about vectors, but the line
Person familj[4];
only creates an array not a vector. If you want to use a vector it would defined as:
std::vector<Person> familj;
or you could use
std::vector<Person> familj[4];
, but it is not necesary with a vector. This will create a vector of classes of type Person where each element is a separate class object.
The line
Person.familj[0] = {"Gustaf", 12};
is not correct. Person is a type and does not have a member familj". What you need is
1 2
|
familj[0].Set("Gustaf", 12);
familj[1].Set("Lina", 14);
|
1 2
|
bubblesort(Person familj[], 4);
linsok(Person familj[], 4, a);
|
are not function calls, but forward declarations. These lines are better used before main or before the function definitions if they are before main. All you need for a function call is:
1 2
|
bubblesort(familj[], 4);
linsok(familj[], 4, a);
|
I have not checked the functions "bubblesort" or "linsok" yet to see if they work.
Hope this helps.
Andy