expected `)' before ‘::’ token

With the below code snip:

1
2
3
4
5
6
7
8
9
10
bool organism_cell::operator==(const organism_cell &O)       // checks for equality

{

	if(this::o_alive == O.status())
		return true;
	else
		return false;

}


o_alive is a char
status() return the value of o_alive in an organism_cell.

It gives me the error "expected `)' before ‘::’ token"

Now, I'm assuming the error lies with the "this::o_alive". but I'm not exactly sure what is should be. I've tried just "o_alive", "status()" and "this.status()" which give the error "passing ‘const organism_cell’ as ‘this’ argument of ‘char organism_cell::status()’ discards qualifiers", as well as "this::status()" which gave the same error as the topic title.

What should I do to fix it?
Thanks for the help.
this is a pointer to the object itself. :: has to do with scope and it doens't make any sense to use it here. What you're looking for is this->o_alive. The -> operator is an operator for pointers to objects used to access membervariables of the object the pointer is pointing to; the previous code is equal to (*this).o_alive. However, simply using o_alive should work to, if o_alive is a membervariable of the class organism_cell.
And then I get the error of "passing ‘const organism_cell’ as ‘this’ argument of ‘char organism_cell::status()’ discards qualifiers", which too me is still clear as mud unfortunately.
organism_cell() is not declared as a const member function, so you cannot call it on a const object (O is declared as const reference).

organism_cell() should be declared as

 
void organism_cell() const;
Topic archived. No new replies allowed.