What is the different between this?
What is the different between this?
Type Foo
Public Function Test(Byval x as Long) As Long;
Private Sub TestSub();
End Type
vs
Type Foo
Declare Function Test(Byval x as Long) As Long;
Declare Sub TestSub();
End Type
Why sometimes I saw access modifiers (Public, Private,...) being used but sometimes only Declare is used?
My impression is there is no rule and people just code the way they like.
Please tell me the different between them and which is the preferred way to code.
Thanks.
Public Function Test(Byval x as Long) As Long;
Private Sub TestSub();
End Type
vs
Type Foo
Declare Function Test(Byval x as Long) As Long;
Declare Sub TestSub();
End Type
Why sometimes I saw access modifiers (Public, Private,...) being used but sometimes only Declare is used?
My impression is there is no rule and people just code the way they like.
Please tell me the different between them and which is the preferred way to code.
Thanks.
Re: What is the different between this?
The most explicit syntax is as follows:
But as by default, a declaration is always public, this other shortened syntax is also valid:
Code: Select all
Type Foo
Public:
Declare Function Test(Byval x as Long) As Long '' public function
As Long l '' public variable
Private:
Declare Sub TestSub() '' private subroutine
As Integer i '' private variable
End Type
Code: Select all
Type Foo
Declare Function Test(Byval x as Long) As Long '' public function
As Long l '' public variable
Private:
Declare Sub TestSub() '' private subroutine
As Integer i '' private variable
End Type
Re: What is the different between this?
No, you're just missing some information, which @fxm provided.miilvyxg wrote:My impression is there is no rule and people just code the way they like.
It all depends on what you need. If you don't need private or protected members, then by all means use unadorned declares. If you're making a highly-structured class hierarchy, then you'll probably need to use protected and possibly private members to achieve the encapuslation and polymorphism you desire.
Re: What is the different between this?
What about constructor? Is something like this right?
Type Foo
Public:
Declare Constructor()
Declare Constructor(Byval x As Long Ptr)
End Type
Type Foo
Public:
Declare Constructor()
Declare Constructor(Byval x As Long Ptr)
End Type
Re: What is the different between this?
What about constructor with a default parameter like this piece of C++ code?
class Foo {
public:
Foo(int x = 256);
}
How could it be correctly translated to FB code?
class Foo {
public:
Foo(int x = 256);
}
How could it be correctly translated to FB code?
Re: What is the different between this?
Yes for the first. For the second:
Code: Select all
class Foo {
public:
Foo(int x = 256);
}
Code: Select all
type Foo
public:
declare constructor( as long = 256 )
end type
Re: What is the different between this?
Seems Byval or Byref must be omitted? I mean should it be Byval as long = 256 or something like that?paul doe wrote:Yes for the first. For the second:Code: Select all
class Foo { public: Foo(int x = 256); }
Code: Select all
type Foo public: declare constructor( as long = 256 ) end type
Re: What is the different between this?
miilvyxg wrote:What about constructor with a default parameter like this piece of C++ code?
class Foo {
public:
Foo(int x = 256);
}
How could it be correctly translated to FB code?
Code: Select all
Type Foo Extends Object
Public:
Declare Constructor(Byval x As Long = 256)
End Type
Re: What is the different between this?
When to Extends Object when not?fxm wrote:miilvyxg wrote:What about constructor with a default parameter like this piece of C++ code?
class Foo {
public:
Foo(int x = 256);
}
How could it be correctly translated to FB code?Code: Select all
Type Foo Extends Object Public: Declare Constructor(Byval x As Long = 256) End Type
Re: What is the different between this?
Many answers to your questions are in the documentation:
FreeBASIC Manual
Maybe you should start there.
FreeBASIC Manual
Maybe you should start there.
Re: What is the different between this?
Indeed I started there (https://www.freebasic.net/wiki/CatPgProgrammer) and can't find the information I want. So I asked.fxm wrote:Many answers to your questions are in the documentation:
FreeBASIC Manual
Maybe you should start there.