Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Function return string

Reply
Thread Tools

Function return string

 
 
streamkid@gmail.com
Guest
Posts: n/a
 
      12-09-2006
Why can't a function not return string? (error: new types may not be
defined in a return type)...
How can i solve it?
I thought of passing the string into the function, but that will make
me redesign most of the app and i want to avoid it.. is there any other
way to overcome this?

tia, streamkid

 
Reply With Quote
 
 
 
 
Ondra Holub
Guest
Posts: n/a
 
      12-09-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) napsal:
> Why can't a function not return string? (error: new types may not be
> defined in a return type)...
> How can i solve it?
> I thought of passing the string into the function, but that will make
> me redesign most of the app and i want to avoid it.. is there any other
> way to overcome this?
>
> tia, streamkid


You wrote here no code, so it is very hard to think, where is your
problem. But there is definitely possible to return strings:

#include <string>
std::string RetString()
{
return "Hello";
}

If you mean returning C-strings, it works too:
const char* RetCString()
{
return "Hello";
}

 
Reply With Quote
 
 
 
 
Signal9
Guest
Posts: n/a
 
      12-09-2006

(E-Mail Removed) wrote:
> Why can't a function not return string? (error: new types may not be
> defined in a return type)...
> How can i solve it?
> I thought of passing the string into the function, but that will make
> me redesign most of the app and i want to avoid it.. is there any other
> way to overcome this?
>
> tia, streamkid



Please paste a snippet of your code. There is nothing stopping you
from returning a class or a C style string.

Also, please post what compiler and OS you are compiling this on.

 
Reply With Quote
 
streamkid@gmail.com
Guest
Posts: n/a
 
      12-09-2006

/ Ondra Holub :
> (E-Mail Removed) napsal:
> > Why can't a function not return string? (error: new types may not be
> > defined in a return type)...
> > How can i solve it?
> > I thought of passing the string into the function, but that will make
> > me redesign most of the app and i want to avoid it.. is there any other
> > way to overcome this?
> >
> > tia, streamkid

>
> You wrote here no code, so it is very hard to think, where is your
> problem. But there is definitely possible to return strings:
>
> #include <string>
> std::string RetString()
> {
> return "Hello";
> }
>
> If you mean returning C-strings, it works too:
> const char* RetCString()
> {
> return "Hello";
> }



thanks for the quick answer

well i tried this and it works :s
BUT
i have
class a
{
public:
string getit();
private:
string astring;
}

i try to compile it and is says the error mentioned above...

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      12-09-2006
(E-Mail Removed) wrote:
> Why can't a function not return string? (error: new types may not be
> defined in a return type)...
> How can i solve it?


Without code, I can only guess that you have forgotten to qualify
'string' with 'std::'.

--
Ian Collins.
 
Reply With Quote
 
streamkid@gmail.com
Guest
Posts: n/a
 
      12-09-2006

/ Signal9 :
> (E-Mail Removed) wrote:
> > Why can't a function not return string? (error: new types may not be
> > defined in a return type)...
> > How can i solve it?
> > I thought of passing the string into the function, but that will make
> > me redesign most of the app and i want to avoid it.. is there any other
> > way to overcome this?
> >
> > tia, streamkid

>
>
> Please paste a snippet of your code. There is nothing stopping you
> from returning a class or a C style string.
>
> Also, please post what compiler and OS you are compiling this on.


i tried on slackware using g++
and on vista using devcpp

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      12-09-2006
(E-Mail Removed) wrote:
>
> well i tried this and it works :s
> BUT
> i have
> class a
> {
> public:
> string getit();


Looks like I made the correct guess.

--
Ian Collins.
 
Reply With Quote
 
Ondra Holub
Guest
Posts: n/a
 
      12-09-2006

(E-Mail Removed) napsal:
> Why can't a function not return string? (error: new types may not be
> defined in a return type)...
> How can i solve it?
> I thought of passing the string into the function, but that will make
> me redesign most of the app and i want to avoid it.. is there any other
> way to overcome this?
>
> tia, streamkid


I think you have defined class without semicolon at the end. Something
like this:

class A
{
} // Here is missing semicolon

int main()
{
}

 
Reply With Quote
 
streamkid@gmail.com
Guest
Posts: n/a
 
      12-09-2006
to both Ondra Holub:
i 've forgot the semicolon only here..

Ian Collins:
no unfortunatelly you haven't. that's not the prob.. i wish it was..

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      12-09-2006
(E-Mail Removed) wrote:
> to both Ondra Holub:
> i 've forgot the semicolon only here..
>
> Ian Collins:
> no unfortunatelly you haven't. that's not the prob.. i wish it was..
>

I haven't what? Please provide context.

--
Ian Collins.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
function doesn't return simply skip the return line hirsh.dan@gmail.com C++ 4 07-22-2008 09:55 AM
Search a Text File for a String, Return String to Function cl@supportreport.org Perl Misc 1 07-29-2006 10:14 PM
Carriage Return added during return of large string from class method Xeno Campanoli Ruby 0 02-13-2006 08:39 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
getting return value from function without return statement. Seong-Kook Shin C Programming 1 06-18-2004 08:19 AM



Advertisments