There is a structure TOut containing inner structure TIn:
template <typename T>
struct TOut
{
struct TIn
{
bool b;
};
TIn in;
T t;
};
How to correctly pass TIn in as a formal parameter of some method?
class Test
{
public:
template <typename T>
static void test ( const TOut<T>::TIn &i) {} //Error
};
int main()
{
TOut <double> o;
Test::test(o.in);
}
The program compiles with the following error:
Error 4 error C2998: 'int test' : cannot be a template definition
Structures and Functions in C : The C Programming allows us to pass the structures as the function parameters.
A nested structure can be passed into the function in two ways: Pass the nested structure variable at once. Pass the nested structure members as an argument into the function.
Structs can be passed as parameters by reference or by value. The default behavior is to pass Struct parameters by reference in partner operations and entries, and to pass them by value in public operations, but it is possible to override this behavior when declaring the parameters.
Structures can be passed as function arguments like all other data types. We can pass individual members of a structure, an entire structure, or, a pointer to structure to a function. Like all other data types, a structure or a structure member or a pointer to a structure can be returned by a function.
You need to use the typename
keyword:
template <typename T>
static void test ( const typename TOut<T>::TIn &i) {}
See Where and why do I have to put the "template" and "typename" keywords?
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