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. VC++ Class Structures

VC++ Class Structures

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadminquestion
3 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.
  • N Offline
    N Offline
    novicedude
    wrote on last edited by
    #1

    Hi, I am developing a client server application with vc++. I have the following 3 main classes * PayrollDlg - This is the main dialog box * WageDlg - This dialog box is accessible thru PayrollDlg * AbsSocket - This class manages the networking aspect i.e creating a socket & sending , receiving data. Now i need to create an object os AbsSocket that can be accessed from both PayrollDlg as well as WageDlg. Where do i declare this object to achieve this. If i declare the AbsSocket object in either PayrollDlg or WageDlg classes it becomes local to that class. What i actually want to know is where is the main() function as if i declare the AbsSocket object in this main it can be accessed anywhere right?

    M D 2 Replies Last reply
    0
    • N novicedude

      Hi, I am developing a client server application with vc++. I have the following 3 main classes * PayrollDlg - This is the main dialog box * WageDlg - This dialog box is accessible thru PayrollDlg * AbsSocket - This class manages the networking aspect i.e creating a socket & sending , receiving data. Now i need to create an object os AbsSocket that can be accessed from both PayrollDlg as well as WageDlg. Where do i declare this object to achieve this. If i declare the AbsSocket object in either PayrollDlg or WageDlg classes it becomes local to that class. What i actually want to know is where is the main() function as if i declare the AbsSocket object in this main it can be accessed anywhere right?

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      You can declare it as global in one cpp file and then declare it using extern in another

      //WageDlg.cpp
      AbsSocket g_AbsSocket;

      //PayrollDlg.cpp
      extern AbsSocket g_AbsSocket;

      or if u want a cleaner way you can do this

      class CGlobalVariables
      {
      static AbsSocket g_AbsSocket;
      };
      CGlobalVariables::AbsSocket g_AbsSocket;

      and include this class in stdafx.h then u can use it like CGlobalVariables::g_AbsSocket whereever u like as for accessing the main function, in MFC it is buried deep under the classes of MFC u can't(shouldn't) access it hope it helps


      C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

      1 Reply Last reply
      0
      • N novicedude

        Hi, I am developing a client server application with vc++. I have the following 3 main classes * PayrollDlg - This is the main dialog box * WageDlg - This dialog box is accessible thru PayrollDlg * AbsSocket - This class manages the networking aspect i.e creating a socket & sending , receiving data. Now i need to create an object os AbsSocket that can be accessed from both PayrollDlg as well as WageDlg. Where do i declare this object to achieve this. If i declare the AbsSocket object in either PayrollDlg or WageDlg classes it becomes local to that class. What i actually want to know is where is the main() function as if i declare the AbsSocket object in this main it can be accessed anywhere right?

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        You could always derive PayrollDlg and WageDlg from a common class where AbsSocket is a member variable.


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        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