Thread: Why can I not do this?

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

    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, "" );
    Double Helix STL

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    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,688
    Yes it was. Doh I should of known better that I had declared the size as read-only..
    Double Helix STL

Popular pages Recent additions subscribe to a feed