Max Frai
Max Frai

Reputation: 64276

Template function in define

I have some template function and I want to call it using define in C++:

#define CONFIG(key, type, def) getValue<type>(key, def);

Of course, it won't work. Could I make something like this?

Upvotes: 4

Views: 241

Answers (1)

Kirill V. Lyadvinsky
Kirill V. Lyadvinsky

Reputation: 99585

It works fine:

template<typename T>
T getValue( int, int ) { return T(); }

#define CONFIG(key, type, def) getValue<type>(key, def);


int main()
{
    CONFIG(1, int, 2);
    return 0;
}

Upvotes: 2

Related Questions