fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. template<typename TContainer>
  8. class GYoba final {
  9. public:
  10. GYoba();
  11.  
  12. int rows() const { return mRows; }
  13. int cols() const { return mCols; }
  14.  
  15. private:
  16. int mRows;
  17. int mCols;
  18. TContainer mData;
  19. };
  20.  
  21. template<typename TValue, int rows, int cols>
  22. using StaticYoba = GYoba<std::array<TValue, rows * cols>>;
  23.  
  24. template<typename TValue>
  25. using DynamicYoba = GYoba<std::vector<TValue>>;
  26.  
  27. template<typename TContainer>
  28. GYoba<TContainer>::GYoba() : mRows(0), mCols(0)
  29. {
  30. }
  31.  
  32. template<typename TValue, int rows, int cols>
  33. template<> StaticYoba<TValue, rows, cols>::GYoba() : mRows(rows), mCols(cols)
  34. {
  35. }
  36.  
  37. int main() {
  38. StaticYoba<double, 3, 3> sYoba;
  39. std::cout << sYoba.rows() << " " << sYoba.cols() << std::endl;
  40. return 0;
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:33:10: error: invalid explicit specialization before '>' token
 template<> StaticYoba<TValue, rows, cols>::GYoba() : mRows(rows), mCols(cols)
          ^
prog.cpp:33:10: error: enclosing class templates are not explicitly specialized
prog.cpp:33:50: error: invalid use of incomplete type 'class GYoba<std::array<TValue, (rows * cols)> >'
 template<> StaticYoba<TValue, rows, cols>::GYoba() : mRows(rows), mCols(cols)
                                                  ^
prog.cpp:8:7: note: declaration of 'class GYoba<std::array<TValue, (rows * cols)> >'
 class GYoba final {
       ^
stdout
Standard output is empty