×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C++
Posted by: Jose Canedo
Added: Feb 6, 2017 2:43 PM
Modified: Feb 6, 2017 3:10 PM
Views: 7
Tags: no tags
when copy assignment operators aren't created
  1. #include <iostream>
  2. #include <string>
  3.  
  4. template<typename T>
  5. class NamedObject
  6. {
  7. public:
  8.     NamedObject(std::string& name, const T& value);
  9. private:
  10.     std::string& nameValue;
  11.     const T objectValue;
  12. };
  13.  
  14. int main()
  15. {
  16.     std::string newDog("Doge");
  17.     std::string oldDog("doggo");
  18.    
  19.     NamedObject<int> p(newDog, 2);
  20.     NamedObject<int> s(oldDog, 36);
  21.     NamedObject<int> j(s); //Ok
  22.     //p = s; copy assignment operator not created because of ref and const
  23. }
  24.