#include <iostream>
class Ship
{
private:
int SXCoord;
int SYCoord;
public:
Ship(int x , int y):SXCoord(x),SYCoord(y){}
};
class Physics
{
private:
int PlayerPos;
int SYCoord;
Ship AllShips[2];
public:
Physics():PlayerPos(1){}
};
The Ship array cant be created because it says
error: no matching function for call to 'Ship::Ship()'|
which i am guessing is because i don't give it any parameters.
But then if i try an assign parameters then it says
error: 'AllShips' declared as function returning an array|
Yeah i tried that as well but it still just says no matching function call.
Either that or i'm doing it wrong.
Would it be possible for you to post working code showing this ?
The compiler maybe thought you were attempting to declare a function with AllShips[]() ?
Did you do this:
Ship Allships[2] (int,int); //Function prototype mixed with a variable
Making AllShips a pointer instead of an array with a fixed size would probably solve two problems:
1) Unlimited size because in the constructor you can dynamically allocate space for Ships* Allships
2) Now you don't have to make a Ships() default constructor because(besides making Allships static) you would have to set all the ships with the same coordinates
Yes, that is wrong as you are mixing variable and function syntax. Allships can only be one or the other.
In the Physics constructor, you can initialize Allships via initializer list. This will assign values to Allships as it is created, not after.
1 2 3 4 5 6
Physics():
PlayerPos(1),
Allships[0](1,1), //Don't hold this to be true; I don't actually
Allships[1](10,10)// know how to initialize member object arrays,
//and this is a guess
{}