Create virtual function with unknown number of parameters

  abstract, c++, templates, virtual

I am looking to have a virtual class used to ensure that all inheriting classes have the following functions

Initialize()
IsInitialized()
Clear()

Maybe there is another approach but the use of the abstract class seems to be the best options as far as I can tell.

The issue is that the Initialize() does not always have the same parameters For example:


class baseObject
{
    virtual void Initialize(...) = 0; //Only want to ensure Initialize is implemented in the inheriting class but parameters may very
    virtual void Clear() = 0;
    virtual bool IsInitialized() = 0;
}

class triangle : public baseObject
{
    virtual void Initialize(double length1, double length2, double length3); //Three parameters
    virtual void Clear();
    vitrual bool IsInitialized();
    ...
}

class square : public baseObject
{
    virtual void Initialize(double baseLength, double baseHeight); //two parameters
    virtual void Clear();
    virtual bool IsInitialized();
    ...
}

etc...

Source: Windows Questions C++

LEAVE A COMMENT