Ecere SDK/eC Forums • View topic - Static methods (::) and this

Ecere SDK/eC Forums

Ecere Developers Community

Static methods (::) and this

General help with the eC language.

Static methods (::) and this

Postby redj » Wed Feb 09, 2011 11:29 am

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?

Posts: 107
Joined: Sun Jan 17, 2010 10:03 am

Re: Static methods (::) and this

Postby jerome » Wed Feb 09, 2011 2:18 pm

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 {

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) { }


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).
Site Admin
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Re: Static methods (::) and this

Postby jfbilodeau » Wed Feb 09, 2011 2:29 pm

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 are not.

Code: Select all

public class Interface
   class_data char * name;

  virtual bool ::Initialize();


Code: Select all
class XInterface : Interface
   class_property(name) = "X";

   // --- User Interface System ---
   bool Initialize()

Posts: 19
Joined: Wed Feb 09, 2011 11:47 am

Re: Static methods (::) and this

Postby jerome » Wed Feb 09, 2011 2:50 pm

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).
Site Admin
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Return to eC Language

Who is online

Users browsing this forum: No registered users and 0 guests