473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Function return string

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

Dec 9 '06 #1
17 6185
st*******@gmail.com 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";
}

Dec 9 '06 #2

st*******@gmail.com 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.

Dec 9 '06 #3

Ï/Ç Ondra Holub Ýãñáøå:
st*******@gmail.com 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...

Dec 9 '06 #4
st*******@gmail.com 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.
Dec 9 '06 #5

Ï/Ç Signal9 Ýãñáøå:
st*******@gmail.com 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

Dec 9 '06 #6
st*******@gmail.com 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.
Dec 9 '06 #7

st*******@gmail.com 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()
{
}

Dec 9 '06 #8
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..

Dec 9 '06 #9
st*******@gmail.com 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.
Dec 9 '06 #10

st*******@gmail.com wrote:
<snip>
>
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...
There is no way you'll get that to compile.
There is no such thing as a string, a std::string maybe and thats only
if you #include <string>.
A class declaration requires a semi-colon.
Any member function you declare needs to be implemented if you plan to
use it.

Dec 9 '06 #11

Ï/Ç Salt_Peter Ýãñáøå:
st*******@gmail.com wrote:
<snip>

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...

There is no way you'll get that to compile.
There is no such thing as a string, a std::string maybe and thats only
if you #include <string>.
A class declaration requires a semi-colon.
Any member function you declare needs to be implemented if you plan to
use it.
well that's not the code!!!!!!!!!!!!!!!!!!!!
i just wrote this to show sth _like_ that i've written and i'm trying
to compile!
ofc i'm not trying to compile this!

Dec 9 '06 #12
st*******@gmail.com wrote:
>
well that's not the code!!!!!!!!!!!!!!!!!!!!
i just wrote this to show sth _like_ that i've written and i'm trying
to compile!
ofc i'm not trying to compile this!
One of the golden rules (and FAQs) for this (and most other language
groups) is "post a compilable example that demonstrates your problem"

--
Ian Collins.
Dec 9 '06 #13
st*******@gmail.com wrote:
>
?/? Salt_Peter ??????:
>st*******@gmail.com wrote:
<snip>
>
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...

There is no way you'll get that to compile.
There is no such thing as a string, a std::string maybe and thats only
if you #include <string>.
A class declaration requires a semi-colon.
Any member function you declare needs to be implemented if you plan to
use it.

well that's not the code!!!!!!!!!!!!!!!!!!!!
Well, then post the code.
i just wrote this to show sth _like_ that i've written and i'm trying
to compile!
Please understand that we cannot see what you have on your screen; we only
see what you post here. If that has errors, we point them out. If those
errors are not the ones you are interested in, don't put them in your posts
in the first place.
ofc i'm not trying to compile this!
See FAQ 5.8.
Best

Kai-Uwe Bux
Dec 9 '06 #14

st*******@gmail.com wrote:
Ï/Ç Salt_Peter Ýãñáøå:
st*******@gmail.com wrote:
<snip>
>
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...
There is no way you'll get that to compile.
There is no such thing as a string, a std::string maybe and thats only
if you #include <string>.
A class declaration requires a semi-colon.
Any member function you declare needs to be implemented if you plan to
use it.

well that's not the code!!!!!!!!!!!!!!!!!!!!
i just wrote this to show sth _like_ that i've written and i'm trying
to compile!
ofc i'm not trying to compile this!
Yes it is code. Until proven otherwise, that is.
If you show us code then ... it IS code.
And that WILL NOT COMPILE.

Dec 9 '06 #15
ok sorry guys.. :(

Dec 9 '06 #16
>
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";
}
HEYY!!!! where were you when i was shouting myself hoarse about the
same topic. you could have solved my problem a millenium ago....

Dec 10 '06 #17
<st*******@gmail.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...

Ï/Ç Signal9 Ýãñáøå:
st*******@gmail.com 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

Okay, please listen closly.
Post WHAT YOU TRIED TO COMPILE THAT DIDN'T COMPILE.
Other than that, the error is in your program on line 42.
Dec 11 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
8
by: Johno | last post by:
I have written the two associated base classes below (Digital_camera and Review) to manage digital camera and review objects. They are base classes for which other derived classes can be written to...
1
by: Saeed Amrollahi | last post by:
Dear All C++ Programmers Hello I am Saeed Amrollahi. I am a software engineer in Tehran Sewerage Company. I try to use std::map and map::find member function. I use Visual Studio .NET. my...
2
by: pangel83 | last post by:
I've been trying for days to write a piece of VB.NET code that will read from winamp's memory space the paths of the files from the current winamp playlist. The GETPLAYLISTFILE command of the...
4
by: Paul | last post by:
Anyone have code that emulates the Nz function in Microsoft Access? In Access it is: Nz(Value as variant, Optional ValueIfNull as Variant) as Variant
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
4
by: default | last post by:
Hello All. I was looking around for a function like strtok() which would tokenize on the complete list of delimiters, rather than tokenize on *any* of the delimiters in the group. I ended up...
27
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1...
20
by: Andrew Morton | last post by:
Is it possible to have two function declarations which take the same parameters but return different types depending on how the function is used? function f(x) as string ' return a string end...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.