View Full Version : ارور multiple definition
mohammad0773
جمعه 29 آبان 1394, 14:33 عصر
سلام.
من یه هدری که خودم ساختم رو به هدر هام اضافه کردم.اگر این هدر رو در یک منبع کد فرابخونی خیلی راحت کار میکنه،اما اگر در دو یا چند منبع فراخوانده بشه ارور multiple definition میده برای مثال multiple definition of `word::check(QString, int)
الآن check یک تابع عضو کلاس word هست.
معمولا برای توابع یا اعضا این ارور رو میده.کسی راه حلی داره
حامد مصافی
جمعه 29 آبان 1394, 20:31 عصر
لطفا کد فایلهای h و cpp این کلاس رو بذارید اینجا
mohammad0773
دوشنبه 02 آذر 1394, 20:51 عصر
سلام.
درواقع یه خلاصه ازشون رو میزارم:
#ifndef HFILE_H
#define HFILE_H
class word{
int score;
public:
char pword[20],eword[20],deword[20],dpword[20];
word(){};
word(const char *EN_word,const char *FA_word){strcpy(eword,EN_word);strcpy(pword,FA_wo rd);}
bool check(const QString Str,const int i);
}w;
//____________________________________________
class wordvector :public QVector<word>{
public:
int flouts();
void sortrand();
void sortrand(wordvector *w);
void del(int i);
void replay(int i);
};
bool word::check(const QString Str,const int i){
char *str;
switch(i){
case 1:
str=eword;break;
case 2:
str=pword;break;
case 3:
str=deword;break;
case 4:
str=dpword;break;
}
if(Str==QString(*str)){
this->score++;
return true;
}
else
return false;
}
#endif // HFILE_H
#include "mainwindow.h"
#include <QApplication>
#include <hfile.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
//main.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <hfile.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
//mainwindow.cpp
#-------------------------------------------------
#
# Project created by QtCreator 2015-11-23T20:58:25
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled23
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h \
hfile.h
FORMS += mainwindow.ui
//untitled.pro
حامد مصافی
سه شنبه 03 آذر 1394, 09:31 صبح
پیادهسازی word::check رو به یک فایل cpp منتقل کنید. در روش شما به ازای هر include یک بار این پیادهسازی تعریف میشود.
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.