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. Deriving from CObject and using = operator

Deriving from CObject and using = operator

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 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.
  • D Offline
    D Offline
    Dr Kuulun
    wrote on last edited by
    #1

    Hello, how is the = operator to be implemented in a class derived from CObject? I derived two classes with one element inside: class CA : CObject { int a; void operator = (const CA& src) {}; } class CB : CA { int b; } The first class overwrites the = operator with an empty function. The following code has a mystic result: CA obA; CB obB; obA.a=1; obA.b=2; obB=obA; The element b is copied, a not. Why? And what do the = operator in CObject? Why is b copied? Do I have to implement the operator in Class CB too? Many questions no answer! Thanx Markus Dr-Kuulun

    V M 2 Replies Last reply
    0
    • D Dr Kuulun

      Hello, how is the = operator to be implemented in a class derived from CObject? I derived two classes with one element inside: class CA : CObject { int a; void operator = (const CA& src) {}; } class CB : CA { int b; } The first class overwrites the = operator with an empty function. The following code has a mystic result: CA obA; CB obB; obA.a=1; obA.b=2; obB=obA; The element b is copied, a not. Why? And what do the = operator in CObject? Why is b copied? Do I have to implement the operator in Class CB too? Many questions no answer! Thanx Markus Dr-Kuulun

      V Offline
      V Offline
      Vytas
      wrote on last edited by
      #2

      class CA : CObject { int a; CA & operator = (const CA &); } good luck Vytas

      1 Reply Last reply
      0
      • D Dr Kuulun

        Hello, how is the = operator to be implemented in a class derived from CObject? I derived two classes with one element inside: class CA : CObject { int a; void operator = (const CA& src) {}; } class CB : CA { int b; } The first class overwrites the = operator with an empty function. The following code has a mystic result: CA obA; CB obB; obA.a=1; obA.b=2; obB=obA; The element b is copied, a not. Why? And what do the = operator in CObject? Why is b copied? Do I have to implement the operator in Class CB too? Many questions no answer! Thanx Markus Dr-Kuulun

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

        How does that even compile? obA.b doesn't make sense.

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

        D 1 Reply Last reply
        0
        • M Michael Dunn

          How does that even compile? obA.b doesn't make sense.

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

          D Offline
          D Offline
          Dr Kuulun
          wrote on last edited by
          #4

          Yes it is wrong. Both objects should be instances from the last derrived class type CB. Dr-Kuulun

          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