std::runtime_error problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

std::runtime_error problems

2,875 Views
javi
Contributor I
I am having problems with this:
 
std::string error_info = "Hello";
std::runtime_error(error_info) --> this doesn't compile
 
but this:
 
std::runtime_error("Hello") --> compile ok.
 
Does anyone know why??
 
Thanks a lot and best regards,
Labels (1)
0 Kudos
1 Reply

385 Views
CompilerGuru
NXP Employee
NXP Employee
You're syntax is defining two error_info variables.
To make it more clear, you code does the same bug as the following simple C code:

int i;
long (i);

So here is how it compiles:

std::string error_info = "Hello";
std::runtime_error runtime_error_name(error_info);


Daniel

PS: Which compiler did you use, and which error message did you get? For mine (CF 6.3), the error message was actually clear, I got

Error : object 'error_info' redefined
main.c line 17 std::runtime_error (error_info);

Daniel
0 Kudos