The type 'myclass' does not have a visible constructor that matches the argument list

Hello,
I’m trying to use class for the first time and I don’t understand what is wrong :

#pragma strict

public class MapBase
{
    public var latitude : float;
    public var longitude : float;

    public function MapBase(latitude:float,longitude:float)
    {
        Debug.Log("MapBase invoked");
        this.latitude = latitude;
        this.longitude = longitude;
    }

    public function getLatitude()
    {
        return latitude;
    }

    public function getLongitude()
    {
        return longitude;
    }
}

public class AutoGPS extends MapBase
{
    public function AutoGPS(latitude : float, longitude : float)
    {
        Debug.Log(this.getLatitude());
    }
}

function Start()
{
var gps:AutoGPS = new AutoGPS(10.32,32.1);
}

the error is :
Assets/NewBehaviourScript.js(28,21): BCE0024: The type ‘MapBase’ does not have a visible constructor that matches the argument list ‘()’.

Thanks for the help !

Your problem is that you have a subclass that has a constructor that does not directly reference a parent constructor.

Thus the parent class is being implicitly constructed using the default constructor which is MapBase()

BUT MapBase does’nt have a default constructor because you declared an explicit constructor.

What you need to do is call the parent classes defined constructor from the child classes constructor like this…`

    #pragma strict
     
     public class MapBase
     {
         public var latitude : float;
         public var longitude : float;
     
         public function MapBase(latitude:float,longitude:float)
         {
             Debug.Log("MapBase invoked");
             this.latitude = latitude;
             this.longitude = longitude;
         }
     
         public function getLatitude()
         {
             return latitude;
         }
     
         public function getLongitude()
         {
             return longitude;
         }
     }
     
     public class AutoGPS extends MapBase
     {
         public function AutoGPS(latitude : float, longitude : float) 
`                 : base(latitude,longitude)
         {
             Debug.Log(this.getLatitude());
         }
     }