gpt4 book ai didi

c++ - 多重定义错误 : How to declare a reference in a header file?

转载 作者:行者123 更新时间:2023-11-30 00:55:25 25 4
gpt4 key购买 nike

qtGUI.o:(.bss+0x0): multiple definition of `R'
rWidgetPlots.o:(.bss+0x0): first defined here
qtGUI.o:(.rodata+0x0): multiple definition of `qtToR'
rWidgetPlots.o:(.rodata+0x0): first defined here
main.o:(.bss+0x0): multiple definition of `R'
rWidgetPlots.o:(.bss+0x0): first defined here
main.o:(.rodata+0x0): multiple definition of `qtToR'
rWidgetPlots.o:(.rodata+0x0): first defined here
moc_qtGUI.o:(.bss+0x0): multiple definition of `R'
rWidgetPlots.o:(.bss+0x0): first defined here
moc_qtGUI.o:(.rodata+0x40): multiple definition of `qtToR'
rWidgetPlots.o:(.rodata+0x0): first defined here

rWidgetPlots.h

#ifndef RWIDGETPLOTSH
#define RWIDGETPLOTSH

#include <iostream>
#include <RInside.h>
#include <Rcpp.h>
#include <vector>
#include <limits>
#include <QRect>
#include <fstream>
#include "zoomAndCornerDatabaseParser.h"

RInside R (0, NULL);
RInside & qtToR (R);

typedef struct
{
double latitude;
double longitude;
unsigned int vehicleId;
} vehicle;

extern std :: vector <vehicle> vehicleInfo;

typedef struct
{
float latitude;
float longitude;
} coordinate;

extern std :: vector <coordinate> previousPoints;

class rdaTilesOnR
{
public:
static std :: string returnCenterPoint (std :: string fileName);
static std :: string findPanningDirection (float newLatitude, float newLongitude,
std :: string topLeftLat, std :: string topLeftLng,
std :: string northEastLat, std :: string northEastLng,
std :: string bottomRightLat, std :: string bottomRightLng,
std :: string southWestLat, std :: string southWestLng);

static void storeVehicleInfo (float latitude, float longitude, unsigned int vehicleId);

static void loadNewTileAndPlotPointsOnRWidget (unsigned short option, float newLongitude, float newLatitude);

static std :: string doesPointLieInBoundaries (unsigned short option, float newLatitude, float newLongitude, float currentCenterLatitude, float currentCenterLongitude);
};

#endif

qtGUI.h

#ifndef QTGUIH
#define QTGUIH

#include <QApplication>
#include <QMainWindow>
#include <QtCore>
#include <QtGui>
#include <QPushButton>
#include <unistd.h>
#include <iostream>
#include <string.h>

#include "rWidgetPlots.h"

class controlRThroughQt : public QWidget
{
Q_OBJECT

QTextEdit *textEdit;

public:
void qtInterface ();

public slots:
void slotPanLeft ();
void slotPanRight ();
void slotPanTop ();
void slotPanBottom ();
void slotZoomIn ();
void slotZoomOut ();
void slotRefresh ();
void findInfoByClicking ();
};

#endif

qtToR 这里是一个引用。它必须在当时和那里定义。如何解决此错误?使用 extern 没有帮助。

最佳答案

It has to defined then and there.

那么,这不可能完成。如果您愿意将其保留在标题中:

extern RInside R;
extern RInside & qtToR;

并将定义移动到单个实现文件中:

//somecpp.cpp
RInside R (0, NULL);
RInside & qtToR (R);

这样就可以了。

关于c++ - 多重定义错误 : How to declare a reference in a header file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12560903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com