Function not recognized by cpp file

I have this function in my header file
1
2
3
4
class fill
{
     image getColor(); //image is defined in another class
}


and I have its definition in a .cpp file
1
2
3
4
image fill::getColor()
{
     return Color; //Color is defined in the other function of this class
}


Now when I call this function in my main, I get this error

getColor() is not a member of fill

But it is a member of fill, it's declared as public and it's syntax is correct as far as I can tell. I spelled everything right, I can't figure out what's wrong.
I have included the header file in the main cpp. There are 2 functions in my fill class, and it will let me call the other one, but not this one.
What you show here is a PRIVATE declaration of getColor() because by default, everything in a class is private. It should be

1
2
3
4
5
class fill
{
public:
    image getColor();
}
Sorry I left that out of the code in the post, I have the public in there in my code.
Show your main().
There may also be a scope issue here, your comment says "Color is defined in the other function of this class" but I do not see a variable named "Color" declared in your class. You cannot return something that does not exist. Also your class is missing a ';'.
Okay that is the whole class definition
The getAverage() function is used to fill the Color variable.

1
2
3
4
5
6
7
8
9
10
class fill
{
   public:
            image getColor();
            void getAverage();
   private:
           image Color;


};


This is the declaration in the main()
1
2
3
4
5
6
for(list<fill*>::iterator current=imageList.begin(); current!=imageList.end(); current++)
{
	fill* Filler = *current;
	image avg = Filler->getAverageColor();
	distance = sqrt((averages[0] - avg.red)^2+(averages[1] - avg.green)^2+ (averages[2] - avg.blue)^2*(timesUsed+1));
}



Last edited on
LOL! Lots of confusion here. Your original post says that your main() calls for getColor(), yet the piece you show does no such thing. Also, you call Filler->getAverageColor(), but there is no such function in your class definition: You have getColor(), or getAverage(), but no getAverageColor().
I just want to add that right now your function "void getAverage()" does absolutly nothing. I am assuming from the 'get' part of the function name that you would like to use this to retrieve data but a void function with no arguments cannot return a value.
I'm trying not to use my actual code cause i'm not sure if i'm allowed to post it, but I don't know any other way to get help. getAverageColor() is what I mean when I say getAverage(). Sorry.

The void function isn't supposed to return anything, it's just supposed to fill up an image object, which is the private variable Color, then i'm getting that variable using the getAverage() function
It still is a mess. If getAverage() == getAverageColor(), then you still expect a return value, but you say it is ok to be returning void.

I'd suggest to get your act together before posting any further. You are just making a mess out of a mess.
I have my act completely together thank you, this is going to work if I could figure out why this won't recognize my function definition, i've never seen this error before, and I know very well how to use classes, I was just hoping someone else had had this happen to them. I'll take it somewhere else
Topic archived. No new replies allowed.