我面临“多重定义”的错误我有3个文件,即currency.h、currency.cpp、main.cpp
在currencyConverter 类下的currencyConverter.h 我做了
using namespace std;
class currencyConverter
{
string result;
stringstream ss;
size_t found,found2;
public:
void getInbetween(string,string);
};
#endif /* CURRENCYCONVERTER_H */
然后在 currencyConverter.cpp 我做了
#include "currencyConverter.h"
void currencyConverter::getInbetween(string selection,string str2,string str3,string sdata)
{
buffer[result.length()] = '\0'; //insert '\0'
char * pch;
pch = strtok (buffer," ");
}
void currencyConverter::webparser(const string siteurl,const string filename)
{
ss << "lynx -dump '" << siteurl << "' > " << filename;
}
string currencyConverter::userOption()
{
//some code
return selection;
}
在 main2.cpp
#include<iostream>
#include"currencyConverter.cpp"
using namespace std;
int main() {
currencyConverter c;
string exitstr;
if(selection!="6")
{
c.webparser(parsePage,"file.txt");
//now perform searchstring
c.searchString(selection,"file.txt");
}
}while (1);
return 0;
}
这是我的制作文件
# ExampleTests Project
SRCS = main2.cpp
HDRS =
PROJ = main
CC = g++
OBJS = $(SRCS:.cpp=.o)
APP = $(PROJ).exe
CFLAGS = -c -g -Wall -I/opt/local/include
ifeq (,$(findstring CYGWIN,$(shell uname)))
LIBS = -lcppunit -ldl
all: $(APP)
$(APP): $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o $(APP) $(LIBS)
clean:
rm -f *.o $(APP)
但是我在编译器上收到此错误
如何获得此修复.. 我没有使用它两次。我用函数 webparser 粘贴了我的 currencyConverter.cpp 的一部分,我在 main2.cpp 调用函数的方式是否有错误?
rm -f *.o main.exe
CLEAN SUCCESSFUL (total time: 86ms)
g++ -c -o main2.o main2.cpp
td::char_traits, std::allocator >)': currencyConverter.cpp:(.text+0xcec): `currencyConverter::webparser(std::basic_string, std::allocator >, std::basic_string, std ::allocator >)' main2.o:main2.cpp:(.text+0xcec): 首先在这里定义 collect2: ld 返回 1 退出状态 make: * [main.exe] 错误 1