K
Kira Yamato
The Boost library has taught me that C++ is powerful enough (by
overloading operators and using templates) to have its syntax and
semantic modified to such an extent that seemingly impossible features
like lambda functions, variant variables, container initializers, etc.
are very possible.
So, I don't want to say too hestantly that it is impossible to simulate
the finalizing of virtual methods and classes in C++.
Hence, I rather turn to the experts and ask if anyone knows if it is
possible to simulate them in any way?
For the problem of finalizing a class, I tried the following way:
template<class A>
class finalized
{
private:
finalized() {}
friend class A; // ERROR: Cannot use template parameter in a
friend statement.
};
class CannotDerived : virtual private finalized<CannotDerived>
{
public:
CannotDerived() {}
};
But this doesn't compile for reason stated in the code. However, I can
modify the above idea into something that works:
class finalized_CannotDerived
{
private:
finalized_CannotDerived() {}
friend class CannotDerived;
};
class CannotDerived : virtual private finalized_CannotDerived
{
public:
CannotDerived() {}
};
This works but not as elegant.
Well, at least I have a way, albeit not so elegant, for finalizing a
class, but I'm still out-of-wit on how to finalize a virtual method.
Moreover, the more I think about it, the more I'm convinced it cannot
be done. I hope someone can prove me wrong here.
overloading operators and using templates) to have its syntax and
semantic modified to such an extent that seemingly impossible features
like lambda functions, variant variables, container initializers, etc.
are very possible.
So, I don't want to say too hestantly that it is impossible to simulate
the finalizing of virtual methods and classes in C++.
Hence, I rather turn to the experts and ask if anyone knows if it is
possible to simulate them in any way?
For the problem of finalizing a class, I tried the following way:
template<class A>
class finalized
{
private:
finalized() {}
friend class A; // ERROR: Cannot use template parameter in a
friend statement.
};
class CannotDerived : virtual private finalized<CannotDerived>
{
public:
CannotDerived() {}
};
But this doesn't compile for reason stated in the code. However, I can
modify the above idea into something that works:
class finalized_CannotDerived
{
private:
finalized_CannotDerived() {}
friend class CannotDerived;
};
class CannotDerived : virtual private finalized_CannotDerived
{
public:
CannotDerived() {}
};
This works but not as elegant.
Well, at least I have a way, albeit not so elegant, for finalizing a
class, but I'm still out-of-wit on how to finalize a virtual method.
Moreover, the more I think about it, the more I'm convinced it cannot
be done. I hope someone can prove me wrong here.