I'd like to use the inferred type from the constructor argument as template arguments throughout the rest of my class. Is this possible?
Something like this:
class AnyClass
{
public:
template<Class C>
AnyClass(C *c) {
//class C is inferred by constructor argument
}
// constructor argument is used as argument in other template types
nestclass<C> myNestedClass;
void randomfunction(C *randonarg) {
}
}
Details:
Here's the thing. I'm trying to initialize my base type given the type of the inheriting class. In the case below DerivedA inherits from Base, but DerivedB inherits from DerivedA, therefore from what I understand the value of this
in the constructor of Base (found in DerivedA) will actually be a pointer to DerivedB therefore the inferred type in Base
will be of type DerivedB. However I'd like to use this type throughout the rest of my Base class and not just limit it to the constructor.
class Base {
// type T derived from inheriting class
template<T>
Base(T *) {};
//like to use other places
void randomfunction(T *arg1) {
//does something with type T
};
}
class DerivedA : publicBase {
DerivedA() : Base(this) { //this should be a pointer to DerivedB, since it is inherited
//from DerivedB.
}
}
class DerivedB : class DerivedA {
//anything
}
**My main goal is to use the inheriting class type in my base class. I realize this is sort of a different qst, but I was thinking my solution would be found somehow in my original question.
I'm thinking using a go-between method (similar to the function proposed below) but not sure if it will work.
Thanks for the help!