Answer the question
In order to leave comments, you need to log in
The template argument is a structure type. How can this type be replaced other than #define NEW_TYPE OLD_TYPE?
Example:
template<typename T> int funcExample(int x, int y) { T s; s.a = x; s.b = y; return s.a + s.b; }
struct Foo{
int a;
int b;
};
#define Bar Foo
int main()
{
int absum = funcExample<Foo>(1, 2);
std::cout << "sum: " << absum << "\n";
absum = funcExample<Bar>(3, 4);
std::cout << "sum: " << absum << "\n";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question