0

Here is my example code

  #include<type_traits>
  #include<stdio.h>
  #include<iostream>
  
  template<
      typename T,
      typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type
      > 
  class Test{
      public:
          Test(T n1);
  };
  
  template<typename T>
  Test<T>::Test(T n1){
    std::cout << n1 << std::endl;
  }

All I want is to make a template class that only accepts arithmetic types for type arguments. However, the compiler throws an error with the implementation.

test.cpp:15:19: error: invalid use of incomplete type ‘class Test<T>’
   15 | Test<T>::Test(T n1){
      |                   ^
test.cpp:9:7: note: declaration of ‘class Test<T>’
    9 | class Test{
      |       ^~~~

What am I doing wrong?

user2762996
  • 566
  • 1
  • 5
  • 16

0 Answers0