Based on the examples provided it seems it should work. However, I get the
compiler error:
c:\users\jon\documents\visual studio
2010\projects\dron\dron\script\script.cpp(29): error C2440: 'initializing' :
cannot convert from 'LuaTempResult::Item' to
'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1>
1> No constructor could take the source type, or constructor overload
resolution was ambiguous
When I change the code somewhat, I get an error better describing the
ambiguity:
1>c:\users\jon\documents\visual studio
2010\projects\dron\dron\script\script.cpp(27): error C2593: 'operator =' is
ambiguous
1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\xstring(772): could be 'std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
1> with
1>
1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\xstring(767): or 'std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
1> with
1>
1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\xstring(762): or 'std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::operator =(const
std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1>
1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\xstring(707): or 'std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::operator
=(std::basic_string<_Elem,_Traits,_Ax> &&)'
1> with
1>
1> while trying to match the argument list '(std::string,
LuaTempResult::Item)'
I'm running Win7 64bit, and using MSVC 2010 Express. Am I doing something
wrong? How can I get this to work?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(This is not relevant to your problem but note that "eval" evaluates an
expression, meaning you do not need to put "return": whatever the expression
evaluates to is returned to the C++ side)
It'll take me a couple days to try it in 2010 as I have been stuck with 2005
for a long time.
You could also try to bypass Item altogether and do
Hi Jon, well it's good to hear that there is a workaround, but it certainly
not great news if static_cast is the only way in VS 2010 Express. So you tried
ret = string(ltr);
and that did not work? Did you try
std::stringret(ltr);
I'm very surprised that these would fail if static_cast works.
Oliver
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ah that is good news, thanks for checking. Yes I agree that if you are
going to cast, then static_cast<> is better than old-style cast. However I
much prefer not to use casting at all, and instead use constructor or
conversion (the two methods that I asked about in my last post). Cheers,
Oliver
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, and thanks for directing me to the forum ;)
I'm experimenting with lua_icxx to see how helpful it might be. I'm having
trouble with this code:
LuaTempResult ltr = _interpreter_ptr->eval( "return 'test'" );
std::string ret = ltr;
Based on the examples provided it seems it should work. However, I get the
compiler error:
When I change the code somewhat, I get an error better describing the
ambiguity:
1>c:\users\jon\documents\visual studio
2010\projects\dron\dron\script\script.cpp(27): error C2593: 'operator =' is
ambiguous
1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\xstring(772): could be 'std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
1> with
1>
1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\xstring(767): or 'std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
1> with
1>
1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\xstring(762): or 'std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::operator =(const
std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1>
1> c:\program files (x86)\microsoft visual studio
10.0\vc\include\xstring(707): or 'std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::operator
=(std::basic_string<_Elem,_Traits,_Ax> &&)'
1> with
1>
1> while trying to match the argument list '(std::string,
LuaTempResult::Item)'
I'm running Win7 64bit, and using MSVC 2010 Express. Am I doing something
wrong? How can I get this to work?
Thanks.
Jon, glad you decided to post. On MS VS 2005 the following snippet works fine:
(This is not relevant to your problem but note that "eval" evaluates an
expression, meaning you do not need to put "return": whatever the expression
evaluates to is returned to the C++ side)
It'll take me a couple days to try it in 2010 as I have been stuck with 2005
for a long time.
You could also try to bypass Item altogether and do
Also try even simpler
Oliver
Jon, I also found that the last example I gave you gets a syntax error with
"ambiguous operator=", which I solved by the following:
This makes me wonder if the following might be necessary in 2010:
(you don't need the because when not given, the first item returned is
automatically used, though adding also works).
Oliver
Thanks for the quick replies. I'll try your suggestions at my earliest
opportunity.
Jon
Yes, my errors were ambiguous operator= errors as well. Following your lead, I
found that casting works:
I'm not knowledgeable enough to know why the 2010 compiler is more picky than
the 2005 compiler, but if casting works, then I'm happy with it ;)
Thanks for your help.
Jon
Hi Jon, well it's good to hear that there is a workaround, but it certainly
not great news if static_cast is the only way in VS 2010 Express. So you tried
and that did not work? Did you try
I'm very surprised that these would fail if static_cast works.
Oliver
Ah, my apologies. Yes, both those approaches work. I just prefer the C++-style
casting since it's easier to spot when skimming code.
Ah that is good news, thanks for checking. Yes I agree that if you are
going to cast, then static_cast<> is better than old-style cast. However I
much prefer not to use casting at all, and instead use constructor or
conversion (the two methods that I asked about in my last post). Cheers,
Oliver