Class-Return Function

I'm having some problems with a class and it's members, I don't know how to return the values.

1
2
3
4
5
6
7
8
9
10
11
12
class CLASS
{
		public:
		void MEMBER(std::string, int);
}
void CLASS::MEMBER(std::string NAME, int AGE)
{
	if (AGE > 18)
	NAME += " is an adult.";
	else
	NAME += " is a child.";
}


I changed NAME, but that doesn't change the value the user sent originally.

1
2
3
4
CLASS Shay9999;
string myname = "Stan Marsh";
Shay9999.MEMBER(myname, 15);
cout<<myname;


When I add a return to it
1
2
3
...else
NAME += " is a child.";
return (NAME);


I get an error that Void is trying to return a value.
Last edited on
Change the arguments from (std::string, int) to (std::string&, int&)

The '&' is just a pointer that automatically gets dereferenced when you use it, rather than you typing '*' before every pointer to access its value.

Why don't you just add name/age to the class though?
I just used them as an example =P and because I'm using a library called SFML, and I want to be able to enter an empty sprite and after it runs through, it becomes filled with an image.

Now that I added the '&' (xD), I'm having some problems altering images. It seems to get a white screen where the image would normally be located. Should I be asking this on the SFML forums, or does somebody here know (^_^)?
The code you have posted has absolutely nothing to do with SFML, or images either. Please post the code you believe is causing the problem (perhaps the code that does stuff with your image...).
Here's the SFML variant.... (Is that the word to use? Variant? I don't know, I think I should using something else)


class CLASS
{
public:
void MEMBER(std::string, sf::Sprite&);
};

void KonGraphs::MEMBER(std::string FILE, sf::Sprite& SPRITE)
{
sf::Image Image;
Image.LoadFromFile(FILE);
SPRITE.SetImage(Image);
}
Last edited on
http://www.sfml-dev.org/tutorials/1.6/graphics-sprite.php
Images and sprites management wrote:
a sprite only points to an external image it doesn't own one
Thanks? I guess =P. No really, though, thanks for the help ^_^
Topic archived. No new replies allowed.