• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sokifilou · Nov 19, 2014 at 12:41 AM · instantiateclassinheritanceconstructors

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 !

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jeff-Kesselman · Nov 19, 2014 at 12:48 AM

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());
          }
      }



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Behind the scenes voodoo w/ Instantiate 2 Answers

Having problem with constructor 3 Answers

Can I call a class's method which inherit monobehaviour by a normal class? 0 Answers

Different sons of inheritance or a different parameter in construction 1 Answer

Instantiate a class 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges