I have some code that is doing the following but I don't understand what the
using BaseTypeX::BaseTypeX is actually doing in this code. The rest of it I understand so please don't explain template specialization etc.
template<typename TReturn, typename... TArgs>
class ClassX<TReturn(TArgs...)> : public Internal::ClassXImpl<TReturn, TArgs...> {
public:
using BaseTypeX = Internal::ClassXImpl<TReturn, TArgs...>;
using BaseTypeX::BaseTypeX; // what is this doing exactly?
inline ClassX() noexcept = default;
// member function
template<class TThis, class TFunc>
inline ClassX(TThis* aThis, TFunc aFunc) {
this->bind(aThis, aFunc); // note bind is implemented in the ClassXImpl class
}
The base type is the type from which the current type directly inherits. Object is the only type that does not have a base type, therefore null is returned as the base type of Object.
A base class, in the context of C#, is a class that is used to create, or derive, other classes. Classes derived from a base class are called child classes, subclasses or derived classes. A base class does not inherit from any other class and is considered parent of a derived class.
The typeof is an operator keyword which is used to get a type at the compile-time. Or in other words, this operator is used to get the System. Type object for a type.
It means you inherit all the constructors of Internal::ClassXImpl<TReturn, TArgs...>. A simpler example might illustrate this better:
struct Foo
{
Foo(int);
Foo(int, double);
Foo(std::string);
};
struct Bar : Foo
{
using Foo::Foo;
};
int main()
{
Bar b1(42); // OK, Foo's constructors have been "inherited"
Bar b2(42, 3.14); // OK too
Bar b2("hello"); // OK
}
Without the using Foo::Foo, you would have to declare and define all the constructors in Bar, and call the respective Foo constructor in each one of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With