I have a template class called RenderShader, I also have a class called Render. I would like to have all instances of the RenderShader template class to be friends with Render. Also the user is allowed to make their own RenderShader instances so it's not possible to list all of them in the main header file. For Example:
template<class vertdef>
class RenderShader
{
public:
.....
};
class Render
{
friend class RenderShader;
public:
....
};
The syntax "friend RenderShader" is wrong, is there a correct syntax for what I would like to do?
Many-to-one: All instantiations of a template function may be friends to a regular non-template class. One-to-one: A template function instantiated with one set of template arguments may be a friend to one template class instantiated with the same set of template arguments.
Can there be more than one argument to templates? Yes, like normal parameters, we can pass more than one data type as arguments to templates.
Template instantiation has two forms: explicit instantiation and implicit instantiation.
It is possible to inherit from a template class. All the usual rules for inheritance and polymorphism apply. If we want the new, derived class to be generic it should also be a template class; and pass its template parameter along to the base class.
class Render
{
template<class vertdef>
friend class RenderShader;
public:
....
};
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