A
anon.asdf
Hello!
1) ===============================
When trying to define an array of std::string ...
func( (std::string []) { std::string("ab"), std::string("cd"),
std::string("ef") } , 3 );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
....g++ tells me: "invalid use of non-lvalue array"
Can the above be modified to work?
void func(std::string arr[], int n)
{
while ((--n) >= 0) {
std::cout << arr[n];
}
}
2)================================
When trying to work with an array of std::string-pointers ...
func2( (std::string* []) { &std::string("ab"), &std::string("cd"),
&std::string("ef") } , 3 );
//
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ~~ nextline
.... g++ reports:
"taking address of temporary" (reported 3 times)
"invalid use of non-lvalue array".
When are the 3 temporary addresses in danger of being "corrupted"? Is
it during the execution of func2, or is it only after func2, i.e.
at // ~~ nextline
How can the error be fixed?
void func2(std::string* arr[], int n)
{
// possible memory allocations etc...
while ((--n) >= 0) {
std::cout << *(arr[n]);
}
}
Thanks for advice!
-Albert
1) ===============================
When trying to define an array of std::string ...
func( (std::string []) { std::string("ab"), std::string("cd"),
std::string("ef") } , 3 );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
....g++ tells me: "invalid use of non-lvalue array"
Can the above be modified to work?
void func(std::string arr[], int n)
{
while ((--n) >= 0) {
std::cout << arr[n];
}
}
2)================================
When trying to work with an array of std::string-pointers ...
func2( (std::string* []) { &std::string("ab"), &std::string("cd"),
&std::string("ef") } , 3 );
//
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ~~ nextline
.... g++ reports:
"taking address of temporary" (reported 3 times)
"invalid use of non-lvalue array".
When are the 3 temporary addresses in danger of being "corrupted"? Is
it during the execution of func2, or is it only after func2, i.e.
at // ~~ nextline
How can the error be fixed?
void func2(std::string* arr[], int n)
{
// possible memory allocations etc...
while ((--n) >= 0) {
std::cout << *(arr[n]);
}
}
Thanks for advice!
-Albert