Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried to implement properties in an "interface"
C++
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900