string - how to define a var in C++ -
this code compiles perfect:
if ( args.length() > 0 ) { if ( args[0]->isstring() ) { string::utf8value szqmn( args[0]->tostring() ) ; printf( "(cc)>>>> qmn [%s].\n", (const char*)(* szqmn) ) ; } ; } ;
but 1 not :
if ( args.length() > 0 ) { if ( args[0]->isstring() ) { string::utf8value szqmn( args[0]->tostring() ) ; // <<<< (a) } ; } ; printf( "(cc)>>>> qmn [%s].\n", (const char*)(* szqmn) ) ; // <<<< (b)
error says : "error c2065: 'szqmn' : undeclared identifier" on line (b)
this means me sentence marked (a) definition @ same time assignement, right ?
and compiler decides "conditionally" defined within 2 "if's" ?
my question : how move declaration out of 2 "if's" ?
in way can give defalut value ... in case if fails.
if write line out of 2 "if's"
string::utf8value szqmn ("") ;
... error :
cannot convert argument 1 'const char [1]' 'v8::handle<v8::value>'
any ideas?
this means me sentence marked (a) definition @ same time assignement, right?
technically constructor call creates variable , initializes it.
also note automatic variables exist until end of scope (usually block inside {} brackets). why second code example not compile.
if (condition) { int x = 5; } x = 6; // error, x not exist anymore
my question : how move declaration out of 2 "if's"?
string::utf8value szqmn ("");
this constructor call of class string::utf8value
class. error message takes parameter of type v8::handle<v8::value>
. without knowing cannot give answer how call it. wanted pass ""
of type const char*
or const char[1]
, compiler telling not take parameter.
edit:
from link deepblackdwarf provided in comment, how create utf8value string:
std::string something("hello world"); handle<value> something_else = string::new( something.c_str() );
so in case do:
string::utf8value szqmn (string::new(""));
Comments
Post a Comment