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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi yal' Can anyone tell me the b

Status
Not open for further replies.

JaybOt

Programmer
Apr 18, 2001
101
GB
hi yal'

Can anyone tell me the best way to return char* from a function/class method. All i need to do is return a string of chars when the func/method is called. I have also tried using ... string myClass::myMethod(void)... but no luck there either.

my code looks like this..

in class ..
char* myClass::myMethod(void);

Use:
char* myClass::myMethod(void) // should return char*
{
return (myClass.hostname);
}

in function ..
char* myFunc(void);

Use:
char* myFunc(void)
{
return(myClass.myMethod())
}

when i try the above, i get error like ..

'cannot resolve overloaded function `myMethod' based on conversion to type `const char *'

can anyone tell me where im going wrong, should I try to return a pointer to the string and set the return type as 'int'??? (tried unsuccessfully) or is there another wasy to acheive this?

Any help would be appreciated, thanks guys..

J@yb0t [afro]

"Always know what you say, but don't always say what you know!"
 
> 'cannot resolve overloaded function `myMethod' based on conversion to type `const char *'

So I'm going to guess your code really looks like:

Code:
class myClass
{
  public:
    char*        myMethod(void);
    const char*  myMethod();
};

and it can't tell which is which, so you want to do:

Code:
class myClass
{
  public:
    char*        myMethod(void);
    const char*  myMethod()
Code:
const
Code:
;
};
 
Don't worry, be happy with stl:string return values. This STL class has an adequate value semantics, its destructors will be automatically invoked at proper moment (no need in garbage collection;).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top