Click here to Skip to main content
14,641,793 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have tried to implement properties in an "interface"
interface IPolygon 
{
  __declspec(property(get = _GetArea)) double area;

  // getters setters
  virtual double _GetArea() const abstract;
};
class  CPoly : public IPolygon
{
    public:
      CPoly(.....) { ......}
    protected:
      // propertis getter/setter
      virtual double _GetArea()    const override { return .. calculation  of area ... }; 
}
.. somewhere in code:
CPoly mypolygon;
double xarea = mypolygon.area;
...
But when using the CPoly-class the linker! says that IPolygon::_GetArea() is not implemented yet. Then changing
interface IPolygon 
{
  __declspec(property(get = _GetArea)) double area;

  // getters setters
  virtual double _GetArea() const { return this->_GetArea(); }
};

calling the getter in the "interface" it will work
but this it not the way it should be ...

Is there a way to define abstract property getters and setters or abstract properties? to get the interface similar to c#.
(this is NOT a question wether it makes sense to use propertis in c++ anyhow!)

What I have tried:

Have tried the above codes and variants
Have debugged b step and when implemnting anything in the virtual fundction in IPolygon (instead of abstract),
the debugger steps into that function and not into the inherited class function (so IPolygon::_GetArea() is called instead of CPoly::_GetArea() )
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100