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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. new mistake class

new mistake class

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
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.
  • U Offline
    U Offline
    unidentify
    wrote on last edited by
    #1

    I create a CRealPoint class: CRealPoint { public: CRealPoint(); CRealPoint(double x=0; double y=0); private: double m_x; double m_y; public: CRealPoint operator=(CRealPoint rPt); } then I have following code: // 1. CArray m_arrPo; 2. CRealPoint tmpPoint; 3. tmpPoint.m_x= // calculate here 4. tmpPoint.m_y=// 5. m_arrPo.Add(tmpPoint); // 6. CRealPoint newPoint; 7. newPoint = m_arr.ElementAt(0); // test value of newPoint.m_x, newPoint.m_y It is lost data. I guess problem occur at line 5 or 7 but don't understand why and don't known how to solve this problem. don't stop me now!!!

    P 1 Reply Last reply
    0
    • U unidentify

      I create a CRealPoint class: CRealPoint { public: CRealPoint(); CRealPoint(double x=0; double y=0); private: double m_x; double m_y; public: CRealPoint operator=(CRealPoint rPt); } then I have following code: // 1. CArray m_arrPo; 2. CRealPoint tmpPoint; 3. tmpPoint.m_x= // calculate here 4. tmpPoint.m_y=// 5. m_arrPo.Add(tmpPoint); // 6. CRealPoint newPoint; 7. newPoint = m_arr.ElementAt(0); // test value of newPoint.m_x, newPoint.m_y It is lost data. I guess problem occur at line 5 or 7 but don't understand why and don't known how to solve this problem. don't stop me now!!!

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

      change these lines 1. CArray <CRealPoint,CRealPoint&> m_arrPo; . . . 6 CRealPoint &newPoint = m_arr.ElementAt(0); // ElementAt return ref to ob or 6 CRealPoint newPoint = m_arr.GetAt(0); // GetAt return ob and need copy constructor that ur class have it. BTW. CRealPoint newPoint = m_arr.ElementAt(0); is also correct :)

      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