VC++ Class Structures
-
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?
-
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?
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
-
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?
You could always derive
PayrollDlg
andWageDlg
from a common class whereAbsSocket
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