![]() |
|
#1
|
|||
|
|||
Writing good header filesHello Guys,
I am not a really got in writing header files. My problem is that no matter how I write the header file, I get the "Multiple definition of..." errors. Here is an example of my header: CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
If I include this header file in my cpp files, I get "Multiple definition of h_module" and "Multiple definition of pFT_ListDevices" errors. Any idea what I'm doing wrong? Thanks and best regards to you all. George Last edited by LuciWiz : 15-May-2005 at 07:22.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#2
|
||||
|
||||
|
Quote:
Hello and Welcome George. How are you using h_module and pFT_ListDevices elsewhere in you program? When you have the variable declaration in your header like you have you would most likely need to declare it in another file (such as your main.cpp) something like the following so you could use it. CPP / C++ / C Code:
That way, the compiler knows how to make sense of it all. That is of course, just a guess based on what you have posted. I have run across this quite often using FLTK's UI builder Fluid since it makes heavy use of externs when it generates it's header code. You can only declare a variable once (as long as it really is the same variable or function) and using extern says, "I need to let the compiler know what this actually is, I need to use it in this section of code, go find it elsewhere." Just be sure extern is the ONLY difference in the two lines of code (same type or return value) or you will get an error. I hope this helps, if not (or if my info is wrong) someone is bound to drop their two cents into the bucket. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#3
|
||||
|
||||
|
Quote:
The header should contain externs and the variable is defined in a code file as cable_guy said. __________________
Age is unimportant -- except in cheese |
Recent GIDBlog
Developing GUIs with wxPython (Part 2) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Writing to Text Files | DesperateCry | C Programming Language | 2 | 19-Apr-2005 07:09 |
| Reading and writing binary files in certain format | Dream86 | C++ Forum | 10 | 06-Aug-2004 10:38 |
| writing to 6 different files | kilgortrout | C++ Forum | 5 | 20-May-2004 17:30 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The