Illegal use of this type as an expression?

Hi,

I am trying to use a function which I have declared in dock class which takes the parameters (Ship &ship)


1
2
3
4
5
6
7
8
9
10
 if (readinsize == 1)
{
    ship->_size = Ship::ShipSizes::SMALL;
			  
	for (int i = 0; i < port._Port.size(); i++)
	{
	    dock.dock(Ship &ship);
	
        }
}


I am getting the error
Error 3 error C2275: 'Ship' : illegal use of this type as an expression


Am I not inputting the required parameters for that function?

Regards
Is ship a class? Everything in a class is private by default, so you can't access your variables directly unless they are after "public:" (which I don't recommend).

ship->_size = Ship::ShipSizes::SMALL;
Is this the line which throws the error?

If so, I recommend using
 
    ship->set_size(Ship::ShipSizes::SMALL);

set_size() could be declared like this:
1
2
3
4
void Ship::set_size(Ship::ShipSizes s=Ship::ShipSizes::SMALL)
{
    _size=s; //or "this->_size=s;"
}
Last edited on
Yes ship is a class.

Apologies the line that throws the error is this

 
dock.dock(Ship &ship);


But honestly I'm not sure what is wrong with this line.

What are you trying to do there on line 7? It looks like some combination of a function call and a definition...

Did you mean to pass ship as a parameter? You don't need to write the type there like that.
http://www.cplusplus.com/doc/tutorial/functions/
Have you tried dock(&ship);?

Your compiler should generate a copy constructor, but there are some reasons why you might want to declare your own. http://www.cplusplus.com/articles/y8hv0pDG/
What gabars said fixed the issue thank you.
Topic archived. No new replies allowed.