Abstract class

Dear All,

I want to create a base class where the arguments of the member function is not known and is known only by the derived class.

The number of arguments and the functionality are common. Hence, the reason for the base class however in one situation, the argument type does not match.

Is it possible for me to solve this ?

Best Regards
Praveen
It sounds like you are actually looking for a template class.

http://cplusplus.com/doc/tutorial/templates/
Last edited on
Can this help you?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Base {
    virtual ~Base() {}
    virtual void Function(int Parameter) = 0;
};

class Derived_A : public Base {
    virtual void Function(int Parameter) {
         // Derived_A's code
    }
};

class Derived_B : public Base {
    virtual void Function(int Parameter) {
         // Derived_B's code
    }
};

// [ ... ]

Derived_A der_a;
Derived_B der_b;
Base * PointerA = &der_a;
Base * PointerB = &der_b;
PointerA->Function(5); // Equals der_a.Function(5)
PointerB->Function(53); // Equals der_b.Function(53) 
You cannot call a virtual function if the argument types do not match. If a derived class has a function that takes a different argument list, then a pure virtual function is not the way to implement a solution to your problem. An abstract base class utilizing a pure virtual function is only really necessary when derived classes will share this functionality.

I want to create a base class where the arguments of the member function is not known and is known only by the derived class.

The number of arguments and the functionality are common.


Can you rephrase your question.
Last edited on
Topic archived. No new replies allowed.