Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaring a class method that will return a string

Status
Not open for further replies.

dgodoy

Programmer
May 24, 2003
1
US
I'm trying to do something fairly simple (I thought), but my Borland C++ 5.5 compiler doesn't like it. I want to declare a method in my class that will return a string value. Here's a SIMPLIFIED example of what I'm talking about:

#ifndef _MESSAGE_H
#define _MESSAGE_H

#include "stdlib.h"
#include <string>

class message{
public:
message();
~message();

string getText(); <-------

private:
string text; <-------
};

#endif

The two lines marked with arrows give me trouble. I recieve errors along the lines of &quot;Expecting a type name&quot;. It seems that strings are not recognized as a type in this context. What am I doing wrong?
 
String *str;

message->getText (str);

class message{
public:
message();
~message();

void getText(String *); <-------

private:
string text; <-------
};

I dont neccessarily like returning strings.

this may help you out.
I would think you need a pointer to the returned string before you can use it.

string *getText();

tomcruz.net

 
My low-resolution eye spys that You uses &quot;string&quot; and butthead uses &quot;String&quot; and as C is case-specific that could be the thing.......

Totte
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top