2

Why is it that calling a static templated method from a class which is passed through template parameters gives me expected primary expression before int compile-time errors:

#include <iostream>

class Singleton
{
public:
    template<typename T>
    static void printSizeOf() { std::cout << sizeof(T) << std::endl; }
};

template<class Class>
void run() { Class::printSizeOf<int>(); }

int main()
{
    run<Singleton>();
    return 0;
}

Yet calling a non-templated version of the static method works just as expected:

#include <iostream>

class Singleton
{
public:
    static void printSizeOfInt() { std::cout << sizeof(int) << std::endl; }
};

template<class Class>
void run() { Class::printSizeOfInt(); }

int main()
{
    run<Singleton>();
    return 0;
}
MaximVarea
  • 21
  • 3

0 Answers0