I would like to take a previously initialized array of objects and be able to set that to a class variable.
I don't have a lot of experience with pointers or great coding style.
This is a snippet of the code that I'm working on which isolates the problem:
#include<cstdlib>
#include<iostream>
using namespace std;
class GameBoard {
string players[];
int total_players;
public:
GameBoard (string given_players[]) {
players = given_players;
total_players = sizeof(given_players)/sizeof(*given_players);
}
};
int main () {
string players[] = {
"Jack",
"Jill"
};
GameBoard gb(players);
return 0;
}
Currently, this code out puts the error:
In constructor 'GameBoard::GameBoard(std::string*)':
[Error] incompatible types in assignment of 'std::string* {aka std::basic_string<char>*}' to 'std::string* [0] {aka std::basic_string<char>* [0]}'