the C++ have virtual functions, but, for me they have 1 problem: on derived class, i must prototype them, for define them on Global Scope.
how can i avoid the re-prototype them on derived class?
i tried 1 way:

template <class Type>
class TypeHasToString
{
    // This type won't compile if the second template parameter isn't of type T,
    // so I can put a function pointer type in the first parameter and the function
    // itself in the second thus checking that the function has a specific signature.
    template <typename T, T> struct TypeCheck;
    typedef char Yes;
    typedef long No;

    // A helper struct to hold the declaration of the function pointer.
    // Change it if the function signature changes.
    template <typename T> struct ToString
    {
        typedef void (T::*fptr)();
    };

    template <typename T> static Yes HasToString(TypeCheck< typename ToString<T>::fptr, &T::MouseClick >*); //function name
    template <typename T> static No  HasToString(...);

public:
    static bool const value = (sizeof(HasToString<Type>(0)) == sizeof(Yes));
};

template <typename CBase>
class test
{
    CBase* atPointer = nullptr;

public:
    void MouseClick(){;};
    test(CBase *clsPointer) : atPointer(clsPointer)
    {
        atPointer=clsPointer;
        //use it:
        std::cout << TypeHasToString<CBase>::value;
    }

    void call()
    {
        atPointer->MouseClick();
    }
};

//ClassWithEvents(test,FormEvents, b);

class InstanceName : public test<InstanceName>
{ // manual expansion of ClassWithEvents
public:
    InstanceName() : test(this){;}

    ~InstanceName(){;}

public:
    void MouseClick();
//  void Move();                       // error 1
} InstanceName;

// void b::MouseClick()                    // possible error 2
void InstanceName::MouseClick()
{
    std::cout << "Mouse click";
}

these template is for test if the class test::CBase have the MouseClick().
these code works, but it's limited: if we have the function prototype(but not defined), i will get '1' instead zero.
so what you can advice me more?

Moderator: i'm sorry, but i can't add the code on same textbox code.. isn't my error :(
edit: i fixed, just for delete the '-' after ':', after new line.. i don't know why

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.