Getting values from functions

I am trying to get values out from several get methods in my class and transfer them to a toString methods to convert them to strings
there are 5 of them. each one returning a different values.


below are the code snippets
string locationData::getSunType(string sunT)
{
return sunT;
}

can i invoke the get methods in this way?

void locationData::toString()
{

cout<<getSunType();

}
Not quite. Your method getSunType takes an object of sunT; however, when you call it, you arend passing in anything. The only whay this will work is if you have getSunType defaulted in its declaration to pass in some default value.
sorry about that. i have another set method which is setSunType which takes in a value via manual input by user

edit :

void locationData::setSunType(string sun)
{
sunType=sun;

}
Last edited on
getSunType (and all other basic accessor functions) don't take any parameters. All it does is return (the value of) a private variable.

Anyway, your proposed method does work, granted that "sunType" is a member variable of type string.

You're not converting anything, though. All you're doing accessing and printing a member variable.
Topic archived. No new replies allowed.