Array Output Error

My program will not output a random value from the array I initialized in the constructor. I can't find any reason that it is only outputting the default case! Please help.Thank you.
Last edited on
We'd need to see what you do with the instance you're talking about.
All the methods are simply called in the main.
Last edited on
Wait a moment.....

1
2
3
    Skill[10] = ("Aweful", "Not So Great", "Decent", "Improving", "Pretty Good", "Awesome", "Super Duper Fantastic");
    Name1[10] = ("Bob", "Titus", "Portia", "Boss", "Elle", "Reba", "Apple", "Kurt", "Bonnie", "Fred");
    Name2[10] = ("White", "Purple", "Orange", "Hog", "Black", "Brown", "Magenta", "Red", "Fuschia", "Teal");


??

You can't do this.

How are Skill/Name1/Name2 defined?
Last edited on
I figured it out! I moved the Arrays into the Setters!
Last edited on
yeah -- you can't initialize them that way. That's not how it works. In fact you're corrupting memory by trying.

Since these are constants in your program, you're better off making them static const:

1
2
3
4
5
6
7
8
9
10
// in your header file:

class Player
{
    //...
    static const string Skill[10];
    static const string Name1[10];
    static const string Name2[10];
    //...
};

1
2
3
4
5
// in your .cpp file:

const string Player::Skill[10] = {"Aweful", "Not So Great", "Decent", "Improving", "Pretty Good", "Awesome", "Super Duper Fantastic"};
const string Player::Name1[10] = //...
//... 


Notice I use {braces}, not (parenthesis). Big difference.

Also note that above initialization would be "global" in the .cpp file (ie: don't put it in your ctor or any other function)


EDIT:

I'm weary that your solution is really a solution. Can you post your solution so I can confirm it for you? What you were trying to do before was wrong on many levels, and simply moving the code wouldn't fix it.
Last edited on
Topic archived. No new replies allowed.