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. Mutual Include

Mutual Include

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialcsharpc++visual-studio
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.
  • Y Offline
    Y Offline
    ytod
    wrote on last edited by
    #1

    It seems using the following scheme would cause problem while building in MS Visual Studio 2005. Can someone give any suggestion on HOW TO ACCESS MEMBER VARIABLE OF b IN a.cpp? Some preprocessor instructions would be appreciated. Thanks a lot. // a.h class b; class a : public A { public: // Constructor, Destructor, and other members and functions. (Omitted) //... // void SomeFunction(); b* m_pb; }; // a.cpp #include "a.h" #include "b.h" void a::SomeFunction() { MEMBERVARIABLEDATATYPE Member_Variable_of_b = m_pb->MemberVariable; // This would cause compiler error } // b.h class a; class b : public B { public: // Constructor, Destructor, and other members and functions. (Omitted) //... // a* m_pa; MEMBERVARIABLEDATATYPE MemberVariable; // MEMBERVARIABLEDATATYPE is well defined, for example, int, double, etc. };

    B 1 Reply Last reply
    0
    • Y ytod

      It seems using the following scheme would cause problem while building in MS Visual Studio 2005. Can someone give any suggestion on HOW TO ACCESS MEMBER VARIABLE OF b IN a.cpp? Some preprocessor instructions would be appreciated. Thanks a lot. // a.h class b; class a : public A { public: // Constructor, Destructor, and other members and functions. (Omitted) //... // void SomeFunction(); b* m_pb; }; // a.cpp #include "a.h" #include "b.h" void a::SomeFunction() { MEMBERVARIABLEDATATYPE Member_Variable_of_b = m_pb->MemberVariable; // This would cause compiler error } // b.h class a; class b : public B { public: // Constructor, Destructor, and other members and functions. (Omitted) //... // a* m_pa; MEMBERVARIABLEDATATYPE MemberVariable; // MEMBERVARIABLEDATATYPE is well defined, for example, int, double, etc. };

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      This works fine so I'm not sure what you are doing to get an error. Output is..."Member variable of b = 22" // b.h ******************** #include "stdafx.h" class a; class b { public: int m_a; b(); virtual ~b(); }; // b.cpp ******************** b::b() : m_a(22) { } b::~b() { } // a.h ******************** #include "stdafx.h" class b; class a { public: void SomeFunction(); b* m_pb; a(); virtual ~a(); }; // a.cpp ******************** a::a() : m_pb(NULL) { m_pb=new b(); SomeFunction(); } a::~a() { if (m_pb) { delete m_pb; } } void a::SomeFunction() { if (m_pb) { int Member_Variable_of_b=m_pb->m_a; TRACE("Member variable of b = %d\n",Member_Variable_of_b); } }

      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