Solved

Convert from String to String *

Posted on 2004-04-25
3
206 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
  • 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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now