Code structure issue

I have a supper class which includes some common functions. The problem i'm facing is, i want to move some similar codes from all derived classes into one function. But those similar code uses one type, which is derived-class related. That means each derived class has its own type definition.

My question, where the common function should be?

I have two ideals about the common function so far:
1. put it in the supper class, using template member function. According to its duty, it should belong to the super class as well.
The problem is, if i put the declare in the header of super class, and put its definition in the implement file of supper class. When invoking it in derived classes, caused LNK 2019 error in VS2010. To resolve that, i have to put the definition of the template function in the header of super class. It's quite bad.
Another solution is to add the .cpp of super class to the projects where derived classes are in, but that cause additional error since it will bring more unnecessary dependence.

2. Create another class/file to put the common function used by all derived classes. I don't think this is good as well. It's a strange structure.

So, any suggestion for this case will be appreciated.

Bellowing is the main structure i have.
1
2
3
4
5
// class super in project s
class super
{
// in super class, it cannot see typeC and typeD.
};

1
2
3
4
5
6
// class derivedA in project da
class derivedA : super
{
// typeC is declared and defined in project da, and cannot move outside of it.
void func(typeC* c); 
};

1
2
3
4
5
6
// class derivedB in project db
class derivedB: super
{
// typeD is declared and defined in project db, and cannot move outside of it.
void func(typeD* d); 
};
how come that you use similar code for different types?

Can't be typeC and typeD be derived from a common class?
Thanks for the reading of the long post and your reply at first. :) I will try to explain the detail problem clearly.

I'm using gSoap for web services accessing, and each web service generates one C++ project. E.g. WebServiceA belongs to project da, WebServiceB belongs to project db.

I created a super class for all web services, the super class is in an independent project, and each project has one derived class for each web service.

For the new function func(), it has to used the type struct soap, which is included in the files generated by the gSoap tools according to each web service. That means each project contains one type with the same name struct soap, but with different definitions. So you know that typeC and typeD are the same names in fact, they are all struct soap*.

The struct soap cannot be moved out of its own project, so i cannot used it in the project where the super class is in.

And then, the problem is here, where should i define the common function func(struct soap*)?

It may also can be done by using MACRO, but that's not a good practice at all.

I'm not sure whether i describe it clear, apologize for any confusion.

Thanks again.
And then, the problem is here, where should i define the common function func(struct soap*)?
well, i'd say that func is not common.

I mean the structure you have looks ok.

if something appears to be too difficult to make it common leave it project specific. Later it may get obvious that not the whole thing is common, but a subset.

[you don't need to desperately try to put everything in a class. Some functions are not ment for it (ie they don't rely on member variables)]
Topic archived. No new replies allowed.