![]() |
|
#1
|
|||
|
|||
Windows C++ Problem with Class and FunctionsOK, a little background first:
I am creating a Windows program using C++ (unmanaged). I am not new to programming, but I am not very experienced. I have an issue that I am having trouble with, and it might be a design issue. Let me try to explain the issue first, without any real code. Because I do not think code is the issue, as much as design and the concept. I know this breaks rule 1, but the code is very trivial. If anyone has programmed in C++ Windows, then you know that alot of functions are loop functions that terminate when certain messages are sent (WM_CLOSE, WM_DESTROY, etc). The rest of the time, the function is in a loop to access mouse, paint, keyboard, and timer messages. Ok, so I have a program that has some child windows, each in a file : Child1File.cpp and Child2File.cpp I also have a class declaration in File3.h (Let's call it CHICKEN). CHICKEN functions are defined in a File3.cpp. In Child1File.cpp, I include File3.h and instantiate an instance of chicken, called egg ( CHICKEN egg ;). I ask for some user input to name the egg, which is a property of CHICKEN..... like so egg.szName = TEXT ("Egghead"). I need to display this property in Child2File.cpp. Now, the problem from what I can gather is that I cannot pass a reference to the egg into the Child2File.cpp function because that is already defined by <windows.h>. (You know HWND, UINT, LPARAM, WPARAM). I obviously cannot instantiate the object in Child2file.cpp because this would create another instance of Chicken, called egg (totally separate from egg instantiated in Child1File.cpp). I could instantiate the egg in any file, but since I cannot pass the information to the function like normal, I am in a bind. So.......would someone be kind enough to show me the error of my reasoning, and a possible solution? Really, if you could just point me to a concept I might read about which would solve this, I would be most certainly grateful. I can post code, if you really want it. |
|||
|
#2
|
|||
|
|||
Re: Windows C++ Problem with Class and FunctionsI am going to include a brief synopsis of the code that I used. This is not complete code, and I did not have to run it through the compiler to know that this will not work. I just cannot think of a solution.
Chicken.h file CPP / C++ / C Code:
Child1.File.cpp (with includes...so that I didnt have to do more files here. I do have separate headers with the prototypes et al. in my own code) CPP / C++ / C Code:
Child2File.cpp CPP / C++ / C Code:
There are alot of elements that I did not include. My code compiles fine if I just want to print text generated from inside of the Child2 function. No problem. Note that this does will not work simply because Child2 has no idea that the egg in Child1 exists. Of course, I could instantiate an egg inside Child2, but then that has nothing to do with the egg in Child1. So, although this is windows code, the question is the same for me in C++. How do I get Child2 to see the egg created in Child1 when the function has already been defined (such is the case with <windows.h>)? |
|
#3
|
|||
|
|||
Re: Windows C++ Problem with Class and Functionsin a header file included by both .cpp files, include
CPP / C++ / C Code:
CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: Windows C++ Problem with Class and FunctionsAh,
so you can declare egg to be extern just like a regular variable. I think that is where I was lost. Interestingly, I haven't found any examples (even in my C++ books) that explicitly say that. Thanks...that should get me going again. |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with class, member functions and consructor | GrassPuppet | C++ Forum | 2 | 04-Feb-2006 18:34 |
| How many member functions within Thing class? | jack223 | C++ Forum | 4 | 08-Nov-2005 10:45 |
| Inheritance problem | CaptnB | C++ Forum | 2 | 27-Jan-2005 09:09 |
| Having problem in calling functions inthe main | harsha | C Programming Language | 1 | 13-Oct-2004 01:05 |
| help with class functions | Mjkramer21 | C++ Forum | 2 | 23-Apr-2004 09:23 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The