Class Inheritance question

Hello all,

I have something like the following classes:
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
26
27
28
class appClass
{
public:

//...

protected:
	inputClass input;
};

class inputClass
{
public:

//...

	virtual void handleInput();
};

void inputClass::handleInput()
{
	//... (generic code for handling input)
}

class derivedAppClass : public appClass
{
	//
};


My purpose is to define a specialized version of handleInput() in my derivedAppClass, so that I can perform generic input processes plus specific tasks within it, like so:

1
2
3
4
5
6
7
//derivedAppClass 's handleInput:
void handleInput()
{
	appClass::input.handleInput();
	
	// (specialized input-handling code should go here)
}


How should I do that? Essentially, I'd like to redefine a virtual function of a member from my base class (appClass::input.handleInput()), in my derived class (derivedAppClass::input.handleInput()).
So far I've come across cases where I've used virtual functions in a derived class of the base class, like this:

1
2
3
4
5
6
7
8
9
10
11
class class1
{
public:
	virtual void f1();
};

class class2 : public class1
{
public:
	void f1();
};
So I'm not sure how to go about something like this.


Thanks in advance for any input, I appreciate it!

EDIT: I guess one way to approach this could be multiple inheritance:

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
26
27
28
29
30
class appClass
{
	//... (no inputClass member defined at all)
};

class inputClass
{
//...
protected:
	virtual void handleInput();
};

void inputClass::handleInput()
{
	// (generic input handling code)
}

class derivedAppClass : public appClass, public inputClass
{
protected:
	void handleInput();
};

void derivedAppClass::handleInput()
{
	inputClass::handleInput();
	
	// (specific input handling code)
	
}


Is there any way to do this as originally specified though? By redefining the virtual function of the protected appClass member through derivedAppClass?
Last edited on
Topic archived. No new replies allowed.