Home

On Oct 4, 7:58 pm, dog <d...@dog.com> wrote:
> I want to have a string array as private member, a then in constructor
> set the values in array, something like this:
>
> class obj{
> string s[];

A C++ array requires a size to be specified for the
number of elements you require.

> public:
> obj(){
> s = {"bla", "blaaa", "..."};

[snip]

You cannot assign to a C++ array like that. You
may be able to assign a new std::string array to
a std::string* pointer, but I don't reccomend it.

I also do not reccomend what you're attempting to
do in the constructor with const string literals.

An appropriae data structure to use here might be a
std::vector<std::string>, which is initialised in the
constructor initialiser list.

--
Chris Val

previous
next

Re: What order does info get returned in by os.listdir()
Re: Is it a good idea to implement constructors with assignment operator?
Re: What is the "functional" way of doing this?
Re: Many Fortran code! How to call Fortran code from C/C++?
req. Unix/SQL/Oracle/JAVA - Work Location US
Kidprotect
Podaruj Zycie
Nasze Dzieci
Niechciane i Zapomniane
Fundacja Avalon