Ecere SDK/eC Forums • View topic - How to write something like an interface ?




Ecere SDK/eC Forums

Ecere Developers Community

How to write something like an interface ?

General help with the eC language.

How to write something like an interface ?

Postby nicktick » Tue Jan 14, 2014 4:01 am

Code: Select all

import "ecere"
class ITest
{
public:
  uint x;
  int  Read(int i);
  void Write();
}

class ITest2 : ITest
{
   uint x;
   int Read(int i)
   {
      return i;
   }
   void Write()
   {
   }
}

class M
{
   bool Test(ITest it)
   {
      it.Read(10);
   }
   int main(int argc,char **argv)
   {
      ITest2 it2{};
      Test(it2);
      return(0);
   }
}


On compiling the above code, the compiler tells:
Linking...
Linker Error: obj/debug.win32/Itest.o: In function `__ecereMethod_M_Test':
Itest.ec:31: error: undefined reference to `__ecereMethod_ITest_Read'
collect2.exe: error: ld returned 1 exit status
nicktick
 
Posts: 17
Joined: Tue Nov 13, 2012 8:34 pm

Re: How to write something like an interface ?

Postby jerome » Tue Jan 14, 2014 4:17 am

Hi nicktick!

eC does not have proper interface support yet (see http://www.ecere.com/mantis/view.php?id=514 for the wishlist feature)

To see what can be done in the current state of things, please take a look at this thread.

To be able to implement multiple interfaces from a single class, interface classes should not contain any data member, and all methods should be virtual and not require a this object, e.g.:

Code: Select all
class ITest
{
public:
  virtual int  ::Read(int i);
  virtual void ::Write();
}


In your case, you were getting this linking error because you declare a non-virtual method without defining it ( no { } body ). The compiler should have reported a compiler error (it's a bug that it did not -- http://www.ecere.com/mantis/view.php?id=1054).
jerome
Site Admin
 
Posts: 622
Joined: Sat Jan 16, 2010 11:16 pm


Return to eC Language

Who is online

Users browsing this forum: No registered users and 3 guests

cron