Why can I not do this?

This is a discussion on Why can I not do this? within the C++ Programming forums, part of the General Programming Boards category; Hi I am working on a basic array question and I am trying to create an array of empty strings. ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479

    Why can I not do this?

    Hi I am working on a basic array question and I am trying to create an array
    of empty strings. I am not permitted to use a vector here.

    I declared the string array correctly and the size is a reference pased from another function.

    Code:
    std::string employeeNames[ rSIZE ] = { "" };
    But I got 1 error saying

    Code:
    salary charter.cpp variable-sized object `employeeNames' may not be initialized
    I do not know why, as say If I had an integer array i could use the { 0 } format to initilize all the elements to zero. Is the a special case for strings that only vectors permit? Of course the below is valid but I cannot use it.

    Code:
    std::vector<std::string> employeeNames ( 10, "" );
    I'm just trying to be a better person - My Name Is Earl

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    rSIZE is not constant?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    Yes it was. Doh I should of known better that I had declared the size as read-only..
    I'm just trying to be a better person - My Name Is Earl

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21