Static methods (::) and this

General help with the eC language.
Post Reply
redj
Posts: 105
Joined: Sun Jan 17, 2010 10:03 am

Static methods (::) and this

Post by redj »

Question from JF:
Do static method (::) have a 'this' parameter passed? Looking at the generated code, it seems to be the case. Is there such a concept as a 'static' (singleton?) class, like GlobalApplicationSettings?

-redj
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Static methods (::) and this

Post by jerome »

In eC, static keeps only the 2 meanings of the C static keyword, that is:

- Visible only inside this source file (.ec)
- static variables inside functions (keeping the same value, just as if they were global)

It doesn't add the third meaning in C++, meaning instance-less.
That is done by defining it with :: in front, but no type before ::, as in:
MyClass {
::MyInstanceLessMethod() { }
}

Note that this syntax comes from the possibility to specify any 'this' type for a method, as in
class MyClass {
MyOtherClass::MyMethod()
}

They do 'not' get a this parameter passed. I don't know which generated code you looked at, but here:

class Form1 : Window {
void ::MyNoThisMethod(int a) { }
}

becomes:

void __ecereMethod_Form1_MyNoThisMethod(int a)

Perhaps you're referring to the Display parameter explicitly added to every method inside the DisplayDriver class, again to work a bit like Java interfaces.

There is no concept of a singleton in eC. If you want a singleton, only create one instance. In eC we don't put 'batons dans les roues' (sticks in the wheels) ;)

A 'static' class in eC is one that is only accessible from within one module.

In eC, one .eC file is usually associated with one class, and any other classes that would serve the purpose of this class. So other classes that do not need to be private/public should typically be made static (except for the limitations mentioned in the other thread about 'static' declarations not possible yet).
jfbilodeau
Posts: 19
Joined: Wed Feb 09, 2011 11:47 am

Re: Static methods (::) and this

Post by jfbilodeau »

Thanks for the reply. Just to confirm my understanding:

:: before a method makes it static.
The static keyword makes it private to the file.

I'm not sure why the gui::Interface class has methods defined as virtual ::, yet the methods within implementations (ie XInterface.er) are not.

Code: Select all

public class Interface
{
public:
   class_data char * name;

  virtual bool ::Initialize();
...
vs

Code: Select all

class XInterface : Interface
{
   class_property(name) = "X";

   // --- User Interface System ---
   bool Initialize()
   {
...
:P
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Static methods (::) and this

Post by jerome »

eC has no function overloading.
So the base class defines the type of 'this' for the method, and says that it is virtual.
There's no need to specify it again when overriding it, and it's not possible to change it either.

Your understanding is right, except that we call the method 'instance-less' as opposed to static in eC to avoid confusion :)
And the 'static' keyword cannot be used with methods at the moment (the noted limitation).
Post Reply