Working in Xcode on Mac OS X Leopard in C++:
I have the following code:
class Foo{
private:
string bars[];
public:
Foo(string initial_bars[]){
bars = initial_bars;
}
}
It does not compile and throws the following error:
error: incompatible types in assignment of 'std::string*' to 'std::string [0u]'
I notice that removing the line bars = initial_bars;
solves the problem.
It seems like I am not doing the assignment correctly. How could I go about fixing this problem?
EDIT:
The variable bars is an array of strings. In the main function I initialize it like this:
string bars[] = {"bar1", "bar2", "bar3"};
But it can contain an arbitrary number of members.
Arrays behave like const pointers, you can't assign pointers to them. You also can't directly assign arrays to each other.
You either
bar
s you get and initialize your member array with its contentsstd
container like std::vector
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With