Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Template Overloading of Non-Mrember Operator [modified]

Template Overloading of Non-Mrember Operator [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiohelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JKallen
    wrote on last edited by
    #1

    I am trying to overload an assignment operator that that assigns an underlying type with the the assignment operator of the template's underlying class. It should be much simpler than creating the syntax of my opening sentence. If anyone can tell me what the hell im doing wrong I would be much obliged. template T& operator=(T& t,const Object& object); template class Object{ friend T& operator=(T& t,const Object& object); public: Object(); //ommitted for brevity protected: Object* m_daddy; T m_data; }; //----------------------------------FOLLOWING IS THE CPP FILE #include "StdAfx.h" #include ".\table.h" template T& operator=(T& t,const Object& object){ t = object.m_data; return t; } template Object::Object(){ //the constructor stuff goes here } I GET THE FOLLOWING ERROR c:\Visual Studio Projects\Statistician Pro\Table.h(5): error C2801: 'operator =' must be a non-static member

    M 1 Reply Last reply
    0
    • J JKallen

      I am trying to overload an assignment operator that that assigns an underlying type with the the assignment operator of the template's underlying class. It should be much simpler than creating the syntax of my opening sentence. If anyone can tell me what the hell im doing wrong I would be much obliged. template T& operator=(T& t,const Object& object); template class Object{ friend T& operator=(T& t,const Object& object); public: Object(); //ommitted for brevity protected: Object* m_daddy; T m_data; }; //----------------------------------FOLLOWING IS THE CPP FILE #include "StdAfx.h" #include ".\table.h" template T& operator=(T& t,const Object& object){ t = object.m_data; return t; } template Object::Object(){ //the constructor stuff goes here } I GET THE FOLLOWING ERROR c:\Visual Studio Projects\Statistician Pro\Table.h(5): error C2801: 'operator =' must be a non-static member

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Read your error message. operator= must be a member of the class, in this case Object.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups