February 10th, 2010, 12:49 PM
Convert Reference To Pointer ?
hi how can i convert a refence to a poiner ?
here is the method :
void Foo(const std::string& s,...)
const std::string* a = s ; //here we will do the conversion.
I tried the following but none of these works :
1) const std::string* a = s ;
error C2440: 'initializing' : cannot convert from std::string' to 'const std::string *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called.
2) const std::string* a = &s ;
compiles, but when run "args" has random junk values
e.g an int passed has value 12300000 instead of 1000.
3) const std::string* a = *s ;
error C2100: illegal indirection
Here what i have done and works, but i am forced to use pointer.
1) int Foo(const std::string* s,...);
OK but user has to call it this way : Foo( &string("MYSTRING") , 1000 )
Which is complecated but works.
2) int Foo(const std::String s,...);
OK but it is slow, user has to wait for the string to get copy constructed.
so is there a workaround ?
thank you for your patience,
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!