Hi,
I am having a small problem learning to include files properly. I think I understand using preprocessor directives to prevent multiple definitions, but it seems I may not understand it well enough. The 3 source files are included in a Project in the IDE. Thank you for your time.
Respectfully,
Mond
Editor/Compiler: Dev-C++ IDE Version 4.9.9.2 Operating System: Windows XP Pro
COMPILER LOG:
000: Compiler: Default compiler
001: Building Makefile: "C:\Dev-Cpp\Makefile.win"
002: Executing make...
003: make.exe -f "C:\Dev-Cpp\Makefile.win" all
004: g++.exe ex43Main.o ex43fd.o -o "Project1.exe" -L"C:/Dev-Cpp/lib" ex43fd.o(.text+0x0):ex43fd.cpp: multiple definition of `Cash::func(int, int)'
005: ex43Main.o(.text+0x100):ex43Main.cpp: first defined here
006: collect2: ld returned 1 exit status make.exe: *** [Project1.exe] Error 1 Execution terminated
SOURCE CODE (in 3 separate files):
000: //Filename:ex43Main.cpp
001:
002: #include <iostream>
003: #include "ex43.h"
004: #include "ex43fd.cpp"
005:
006: using namespace std;
007:
008: int main (int argc, char* argv[])
009: {
010: Cash mycash;
011: for (int i=0; i<5; i++) cout<<"mycash.func("<<i<<", "<<i+5<<")="<<
012: mycash.func(i, i+5)<<endl;
013: system("pause");
014: return 0;
015: }// end of function main
016:
000: //Filename:ex43fd.cpp Cash Member Function Definitions
001:
002: #include "ex43.h"
003:
004: int Cash::func(int i, int j)
005: {
006: return i*j;
007: }// end of Cash member function func
008:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-09-07
1.- Erase this line from the source ex43Main.cpp
include "ex43fd.cpp"
2.- Include the file ex43fd.cpp in your's project (if it isn't already included)
Old Newbie.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am having a small problem learning to include files properly. I think I understand using preprocessor directives to prevent multiple definitions, but it seems I may not understand it well enough. The 3 source files are included in a Project in the IDE. Thank you for your time.
Respectfully,
Mond
Editor/Compiler: Dev-C++ IDE Version 4.9.9.2 Operating System: Windows XP Pro
COMPILER LOG:
000: Compiler: Default compiler
001: Building Makefile: "C:\Dev-Cpp\Makefile.win"
002: Executing make...
003: make.exe -f "C:\Dev-Cpp\Makefile.win" all
004: g++.exe ex43Main.o ex43fd.o -o "Project1.exe" -L"C:/Dev-Cpp/lib" ex43fd.o(.text+0x0):ex43fd.cpp: multiple definition of `Cash::func(int, int)'
005: ex43Main.o(.text+0x100):ex43Main.cpp: first defined here
006: collect2: ld returned 1 exit status make.exe: *** [Project1.exe] Error 1 Execution terminated
SOURCE CODE (in 3 separate files):
000: //Filename:ex43Main.cpp
001:
002: #include <iostream>
003: #include "ex43.h"
004: #include "ex43fd.cpp"
005:
006: using namespace std;
007:
008: int main (int argc, char* argv[])
009: {
010: Cash mycash;
011: for (int i=0; i<5; i++) cout<<"mycash.func("<<i<<", "<<i+5<<")="<<
012: mycash.func(i, i+5)<<endl;
013: system("pause");
014: return 0;
015: }// end of function main
016:
000: //Filename:ex43.h Structure Declaration
001:
002: #ifndef EX43_H
003: #define EX43_H
004:
005: struct Cash
006: {
007: int func(int, int);
008: };
009:
010: #endif //EX43_H
011:
000: //Filename:ex43fd.cpp Cash Member Function Definitions
001:
002: #include "ex43.h"
003:
004: int Cash::func(int i, int j)
005: {
006: return i*j;
007: }// end of Cash member function func
008:
1.- Erase this line from the source ex43Main.cpp
include "ex43fd.cpp"
2.- Include the file ex43fd.cpp in your's project (if it isn't already included)
Old Newbie.
Thank you Old Newbie.
Mond