Click here to Skip to main content
15,914,642 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: #pragma once, #ifndef problem Pin
Jörgen Sigvardsson18-Dec-05 9:02
Jörgen Sigvardsson18-Dec-05 9:02 
GeneralRe: #pragma once, #ifndef problem Pin
#realJSOP16-Dec-05 10:23
professional#realJSOP16-Dec-05 10:23 
GeneralRe: #pragma once, #ifndef problem Pin
werfel16-Dec-05 10:27
werfel16-Dec-05 10:27 
AnswerRe: #pragma once, #ifndef problem Pin
Nemanja Trifunovic16-Dec-05 10:56
Nemanja Trifunovic16-Dec-05 10:56 
GeneralRe: #pragma once, #ifndef problem Pin
werfel16-Dec-05 11:04
werfel16-Dec-05 11:04 
GeneralRe: #pragma once, #ifndef problem Pin
Jörgen Sigvardsson16-Dec-05 12:26
Jörgen Sigvardsson16-Dec-05 12:26 
GeneralRe: #pragma once, #ifndef problem Pin
werfel16-Dec-05 14:47
werfel16-Dec-05 14:47 
GeneralRe: #pragma once, #ifndef problem Pin
Jörgen Sigvardsson16-Dec-05 23:15
Jörgen Sigvardsson16-Dec-05 23:15 
werfel wrote:
i'm putting a class definition in the header. isn't that where they're supposed to be?

You can do that, but then you'd have to tag the methods with inline, or put the method bodies within the class. It's easiest to do the latter. Kind of like C#:
class X {
     void method() {
           // code here
     }
};
werfel wrote:
i would then have to #include the .cpp in the .h, which i understand to be a big no-no.

Indeed! What you need to investigate is how to create static (.lib) or dynamic libraries (.dll). A good start is learning how to use and create static libraries, since there are less details to keep in mind.

Basically, a library consists of two things: header files and a .lib-file. The header files instructs the compiler at compile time that the classes and functions are available for linking. The .lib file provides the actual code and data for the linker, so that the names referenced in the header file will be bound to the corresponding code and/or data.

One could say that the linker is the part of the compiler toolkit that puts all the pieces together. The pieces are typically .lib and .obj files. The .obj files are produced by the compiler for each compilation unit. In a C++ project, the .cpp files are compilation units. If you have #included code bodies (such as functions, not prototypes) into several .cpp files, the linker will find duplicates of the code. Since the preprocessor is basically a cut'n'paster (#include basically pastes whatever is in the inluded file), the linker can't know that the found duplicates are the same. It will have to refuse linking. This is the linker error you got.


--
Pictures[^] from my Japan trip.

-- modified at 14:59 Sunday 18th December, 2005
QuestionAudio pitch/time shift Pin
Hedphoniks16-Dec-05 9:58
Hedphoniks16-Dec-05 9:58 
QuestionC++ noob ?: Show a window in a DLL Pin
James Coleman16-Dec-05 9:53
James Coleman16-Dec-05 9:53 
QuestionEmpty String Overkill Pin
Blake Miller16-Dec-05 8:16
Blake Miller16-Dec-05 8:16 
AnswerRe: Empty String Overkill Pin
grigsoft16-Dec-05 9:04
grigsoft16-Dec-05 9:04 
AnswerRe: Empty String Overkill Pin
Tim Smith16-Dec-05 11:44
Tim Smith16-Dec-05 11:44 
GeneralRe: Empty String Overkill Pin
Jörgen Sigvardsson16-Dec-05 12:27
Jörgen Sigvardsson16-Dec-05 12:27 
AnswerRe: Empty String Overkill Pin
David Crow16-Dec-05 15:00
David Crow16-Dec-05 15:00 
AnswerRe: Empty String Overkill Pin
VikramDelhi16-Dec-05 20:40
VikramDelhi16-Dec-05 20:40 
QuestionChange CStatic runtime? Pin
PatP0716-Dec-05 7:46
PatP0716-Dec-05 7:46 
AnswerRe: Change CStatic runtime? Pin
Nish Nishant16-Dec-05 7:47
sitebuilderNish Nishant16-Dec-05 7:47 
GeneralRe: Change CStatic runtime? Pin
PatP0716-Dec-05 8:54
PatP0716-Dec-05 8:54 
GeneralRe: Change CStatic runtime? Pin
Nish Nishant16-Dec-05 9:06
sitebuilderNish Nishant16-Dec-05 9:06 
GeneralRe: Change CStatic runtime? Pin
Nish Nishant16-Dec-05 9:08
sitebuilderNish Nishant16-Dec-05 9:08 
GeneralRe: Change CStatic runtime? Pin
PatP0716-Dec-05 10:22
PatP0716-Dec-05 10:22 
GeneralRe: Change CStatic runtime? Pin
Jörgen Sigvardsson16-Dec-05 12:43
Jörgen Sigvardsson16-Dec-05 12:43 
QuestionHow to execute an exe Pin
VikramDelhi16-Dec-05 3:12
VikramDelhi16-Dec-05 3:12 
AnswerRe: How to execute an exe Pin
toxcct16-Dec-05 3:47
toxcct16-Dec-05 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.