Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 多定义错误:如何在头文件中声明引用?_C++_Qt_Reference_Header - Fatal编程技术网

C++ 多定义错误:如何在头文件中声明引用?

C++ 多定义错误:如何在头文件中声明引用?,c++,qt,reference,header,C++,Qt,Reference,Header,rWidgetPlots.h 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

rWidgetPlots.h

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
#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
#ifndef RWIDGETPLOTSH
#定义RWIDGETPLOTSH
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“zoomAndCornerDatabaseParser.h”
漂洗液R(0,空);
冲洗液和QTOR(R);
类型定义结构
{
双纬度;
双经度;
未签名的int vehicleId;
}车辆;
外部标准::矢量车辆信息;
类型定义结构
{
浮动纬度;
浮动经度;
}协调;
外部标准::向量优先点;
类rdaTilesOnR
{
公众:
静态std::string returnCenterPoint(std::string文件名);
静态标准::字符串FindPlanningDirection(浮点新纬度、浮点新经度、,
std::string topLeftLat,std::string topLeftLng,
标准::字符串东北纬度,标准::字符串东北LNG,
std::string bottomRightLat,std::string bottomRightLng,
标准:串西南纬度,标准:串西南LNG);
静态void storeVehicleInfo(浮动纬度、浮动经度、无符号整数vehicleId);
静态void loadnewileandplotpointsonrwidget(无符号短选项、浮点新经度、浮点新纬度);
静态std::string DoesPointInBoundaries(无符号短选项、浮点新纬度、浮点新经度、浮点currentCenterLatitude、浮点currentCenterLatitude);
};
#恩迪夫
qtGUI.h

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
#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
#ifndef QTGUIH
#定义QTGUIH
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“rWidgetPlots.h”
类控件rthrawqt:publicqwidget
{
Q_对象
QTextEdit*文本编辑;
公众:
void接口();
公众时段:
void slotPanLeft();
void slotPanRight();
void slotPanTop();
void slotPanBottom();
void slotZoomIn();
void slotZoomOut();
void slotRefresh();
单击()将findinfo作废;
};
#恩迪夫
QTOR
这里是一个参考。它必须在那时和那里定义。如何解决此错误?
使用
extern
没有帮助

它必须在那时和那里定义

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

#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
并将定义移动到单个实现文件:

extern RInside R;
extern RInside & qtToR;
那就行了

它必须在那时和那里定义

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

#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
并将定义移动到单个实现文件:

extern RInside R;
extern RInside & qtToR;

那就行了。

啊,我不知道extern也可以被用作w.r.t参考!谢谢,这很有帮助。啊,我不知道extern也可以用作w.r.t参考资料!谢谢,这很有帮助。