Create an instance of a class inside another class

I am new to C ++ like in Qt. I have the following problem: I want to instantiate a CLEyeCameraCapture object in the public portion of the Qt header, however I get heaps of syntax errors from CLEyeCameraCapture.h.

I get the following (German) syntax errors:

CLEyeCameraCapture.h (7): error C2146: Syntaxfehler: Fehlendes ';' VOR Bezeichner '_windowName' CLEyeCameraCapture.h (7): error C4430: Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C ++ nicht unterstützt.

CLEyeCameraCapture.h (7): error C4430: Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C ++ nicht unterstützt.

CLEyeCameraCapture.h (8): error C2146: Syntaxfehler: Fehlendes ';' VOR Bezeichner '_cameraGUID' CLEyeCameraCapture.h (8): error C4430: Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C ++ nicht unterstützt.

... and so on...

Thanks in advance for any help. Here is my code:

qtdevc.h (header of my application class)

#ifndef QTDEVC_H #define QTDEVC_H #include <QtGui/QMainWindow> #include "ui_qtdevc.h" #include <QString> #include <QDebug> #include <CLEyeCameraCapture.h> #include <stdafx.h> class qtDEVC : public QMainWindow { Q_OBJECT public: qtDEVC(QWidget *parent = 0, Qt::WFlags flags = 0); ~qtDEVC(); Ui::qtDEVCClass ui; CLEyeCameraCapture::CLeyeCameraCapture cam; private: QPushButton *PushButton_startCam; QPushButton *PushButton_stopCam; QPushButton *PushButton_startLogging; QPushButton *PushButton_quit; QLineEdit *lineEditID; // begin new code public slots: int startCam(); void stopCam(); void quit(); // end new code }; #endif // QTDEVC_H 

CLEyeCameraCapture.h

 #ifndef CLEYECAMERACAPTURE_H #define CLEYECAMERACAPTURE_H // Sample camera capture class class CLEyeCameraCapture { CHAR _windowName[256]; GUID _cameraGUID; CLEyeCameraInstance _cam; CLEyeCameraColorMode _mode; CLEyeCameraResolution _resolution; float _fps; HANDLE _hThread; bool _running; std::string _participant; public: CLEyeCameraCapture(LPSTR windowName, GUID cameraGUID, CLEyeCameraColorMode mode, CLEyeCameraResolution resolution, float fps) : _cameraGUID(cameraGUID), _cam(NULL), _mode(mode), _resolution(resolution), _fps(fps), _running(false) { strcpy(_windowName, windowName); } double GetRandomNormalized(); bool StartCapture(std::string ID); void StopCapture(); void IncrementCameraParameter(int param); void DecrementCameraParameter(int param); void Run(); static DWORD WINAPI CaptureThread(LPVOID instance); }; 

My Qt App (not yet cleared)

 #include "qtdevc.h" #include <QtGui> #include <QDebug> #include <QtGui/QApplication> #include "stdafx.h" #include "CLEyeCameraCapture.h" using namespace std; qtDEVC::qtDEVC(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { ui.setupUi(this); connect (ui.pushButton_startCam, SIGNAL( clicked() ),this,SLOT( startCam() ) ); connect (ui.pushButton_quit, SIGNAL( clicked() ),this,SLOT( quit() ) ); connect (ui.pushButton_stopCam, SIGNAL ( clicked() ),this,SLOT( stopCam() ) ); } qtDEVC::~qtDEVC() { } //get ID of participant int qtDEVC::startCam() { //qt part //ui.startCam->setText("Hi!"); QString ID; //get qString Participant Number ID = ui.lineEditID->text(); //convert to standard string std::string IDString = ID.toLocal8Bit().constData(); //qDebug()<<ID; ui.lineEditID->setDisabled(true); ui.pushButton_startCam->setDisabled(true); //moved this to here from main CLEyeCameraCapture *cam[2] = { NULL }; srand(GetTickCount()); // Query for number of connected cameras 

...

change

including

"# include" before "#include" in qDEVC.h

solved the problem with syntax errors in compilation, but now I get errors C2146, C3210 and C2602 when I tried to put into action

 CLEyeCameraCapture::CLeyeCameraCapture cam; 

What is the right way?

 CLEyeCameraCapture::CLeyeCameraCapture *cam[2]; ?? 
+4
source share
2 answers

To fix a compilation error,

 Please Include "#include <stdafx.h>" before "#include <CLEyeCameraCapture.h>" in qDEVC.h. 

for more information Compiler Error C2146

Rule: It is best to include standard headers first and then your own headers. C ++ header order

+2
source

Your compiler does not know what a CHAR or GUID is. Include the necessary Windows header files so that the compiler knows the definition of these data types. Probably just windows.h might be enough.

0
source

Source: https://habr.com/ru/post/1499097/


All Articles