A little contradiction with Declare Sub Constructor in a udt

General FreeBASIC programming questions.
Post Reply
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

A little contradiction with Declare Sub Constructor in a udt

Post by Tourist Trap »

Hello,

I noticed that declaring a Sub named Constructor fires an error message as follows
error 4
duplicated definition, found 'constructor' ...
But, if you did actually no't declare the constructor, you will be told that:
error 18
element not defined
(if you call the routine member named constructor that you are told is defined)

If we extends from OBJECT all turns correct however.

Code to play with to understand fully this (small) issue:

Code: Select all

type T  ' extends OBJECT
  declare sub constructor()
  as integer ii
end type

dim tt as T
tt.constructor()
So even for the non extended from OBJECT stuff, a constructor (empty) should apparently exist. Or the messages are contradictory.

Thanks!
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: A little contradiction with Declare Sub Constructor in a udt

Post by fxm »

Since fbc 0.18.3, this is that same error message which is reported when attempting to use a reserved name forbidden in a specific context:

Code: Select all

Type UDT1
  Dim As Integer Constructor  '' OK
  Dim As Integer Implements   '' OK
  Dim As Integer Class        '' OK
End Type

Type UDT2
  Declare Sub Constructor ()  ''error 4: Duplicated definition
  Declare Sub Implements ()   ''error 4: Duplicated definition
  Declare Sub Class ()        ''error 4: Duplicated definition
  Dim As Integer I
End Type
There is no error message of the type "reserved keyword".
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: A little contradiction with Declare Sub Constructor in a udt

Post by Tourist Trap »

fxm wrote:There is no error message of the type "reserved keyword".
Ah that's the explanation. Thanks fxm!
Post Reply