fork download
  1. #include <cstddef> //size_t
  2. template<size_t SIZE>
  3. class FixedString
  4. {
  5. public:
  6. operator const char*();
  7. void operator =(const char*);
  8.  
  9. void operator =(const FixedString&);
  10.  
  11. // Disallow
  12. private:
  13. template<size_t OTHERSIZE>
  14. void operator=(const FixedString<OTHERSIZE>&);
  15. };
  16.  
  17. int main()
  18. {
  19. FixedString<10> buf1;
  20. FixedString<20> buf2;
  21.  
  22. buf2 = buf1; // NO ERROR!!
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:14:10: error: ‘void FixedString<SIZE>::operator=(const FixedString<OTHERSIZE>&) [with unsigned int OTHERSIZE = 10u; unsigned int SIZE = 20u]’ is private
prog.cpp:22:12: error: within this context
stdout
Standard output is empty