?
Solved

Convert from String to String *

Posted on 2004-04-25
3
Medium Priority
?
211 Views
Last Modified: 2010-04-01
Is there a way to convert a String to a String *?
say a function :
String A_func();

I want to convert whatever returned by A_func to a String* (in VC++.net format)
0
Comment
Question by:lordiano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10915581
You need to provide more details. I don't think it is possible to write function like

String A_func();

Compiler doesn't allow this for reference types.
0
 
LVL 12

Accepted Solution

by:
stefan73 earned 500 total points
ID: 10916262
Hi lordiano,
If it is your own function which needs a string*, rewrite it to string&. Pointers are evil :-)

Otherwise, you need a temporary var:
string temp=A_func();
call_other_func(&temp); // -> string*


Cheers,
Stefan
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10916271
BTW: Since string& and string* are very closely related, you could also try if an implicit typecast is done when you do

string* A_func();

...but I'm not sure.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question