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. Managed C++/CLI
  4. Operator= Overloading

Operator= Overloading

Scheduled Pinned Locked Moved Managed C++/CLI
questionhelp
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.
  • O Offline
    O Offline
    od ananzi co za
    wrote on last edited by
    #1

    Hi All, I'm trying to overload the assignment (=) operator so that I can achieve the following: int x = myclass; instead of: int x = myclass.Value(); I am implementing it as follows: class CMyClass { private: int m_nValue; public: int& operator=(CMyClass& class); int Value() { return m_nValue; }; }; int& CMyClass::operator=(CMyClass& class) { return class.Value(); } But I keep on getting a compiler errors either saying that there is no suitable conversion, or that it cannot convert from CMyClass to int. Clearly my syntax (or something) is screwed, so how can I fix it ? Thanks OD

    P 1 Reply Last reply
    0
    • O od ananzi co za

      Hi All, I'm trying to overload the assignment (=) operator so that I can achieve the following: int x = myclass; instead of: int x = myclass.Value(); I am implementing it as follows: class CMyClass { private: int m_nValue; public: int& operator=(CMyClass& class); int Value() { return m_nValue; }; }; int& CMyClass::operator=(CMyClass& class) { return class.Value(); } But I keep on getting a compiler errors either saying that there is no suitable conversion, or that it cannot convert from CMyClass to int. Clearly my syntax (or something) is screwed, so how can I fix it ? Thanks OD

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      This forum is meant for managed C++. You have rightly asked it in VC++[^] forum. So, please dont cross-post.

      Prasad Notifier using ATL | Operator new[],delete[][^]

      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