“funny” thing happened:
Note: Vector3 is struct 3xfloat coordinates x,y,z
class Teleport {
Vector3 currentPosition;
Vector3 destinationPosition;
Teleport(Vector3 currentPosition, Vector3 destinationPosition)
{
this.currentPositon = currentPositon;
this.destinationPosition = destinationPosition;
//...
}
}
When I cast this code from another class, here we have a problem:
Note: arrays teleportPositions and destinationPositions are type Vector3[]
and they’re not empty
Teleport[] teleportList = new Teleport[NUMBER_OF_TELEPORTS]
for (int i = 0; i < NUMBER_OF_TELEPORTS; i++)
{
Vector3 actual = teleportPositons[i];
Vector3 dest = destinatonPositions[i];
teleportList[i] = new Teleport(actual,dest); //there is the problem
}
Visual studio says:‘Semestralwork.Teleport’ does not contain a constructor that takes 2 argument.
Semestralwork is a namespace, all classes are in this namespace.
I don´t understand it but I thing I can still count to two :/
Does anyone now?
Thanks.
The default access modifier for the constructor is listing it as private, which means it can only be accessed from within the
Teleportclass. You want it to bepublic(orinternalwhich it essentially would be based on the class’ access modifier defaulting tointernal), as follows: