access variable by pressing address
Feb 21, 2020 at 7:13am UTC
Hello , I wanna use Instance w to access _x by pressing address (OlMain->vref->_x=10;) through ui_MainWidow::setupUI function, but when i compile this program then issues only 1 error: use of undefined type 'OlMainWindow'
help me for this error, thank so much.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
My code File:
FILE ui_MainWidow.h
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <iostream>
#include "olvalue.h"
class OlValue;
class OlMainWindow;
class ui_MainWidow;
class ui_MainWidow {
public :
void setupUI(OlMainWindow* OlMain) {
OlMain->vref->_x=10; // _x = 10;
OlMain->vref->_x = 10;
std::cout << " ok" ;
}
};
#endif //UI_MAINWINDOW_H
FILE olvalue.h
#include <iostream>
#ifndef VALUE_H
#define VALUE_H
#include "ui_mainwindow.h"
class OlValue;
class OlMainWindow;
class ui_MainWidow;
class OlValue
{
public :
int _x;
int _y;
public :
OlValue() {
_x = 10;
_y = 20;
}
};
#endif //VALUE_H
FILE olmainwindow.h
#ifndef OLMAINWINDOW_H
#define OLMAINWINDOW_H
#include <iostream>
#include <string>
#include "olvalue.h"
class OlValue;
class OlMainWindow;
class ui_MainWidow;
class OlMainWindow
{
public :
OlValue* vref = new OlValue;
OlMainWindow();
~OlMainWindow();
void enterUsername();
private :
int val;
std::string _Username;
};
#endif //OLMAINWINDOW_H
FILE olmainwidow.cpp
#include "olmainwindow.h"
#include <iostream>
#include <string>
class OlValue;
class OlMainWindow;
class ui_MainWidow;
OlMainWindow::OlMainWindow() {
ui_MainWidow* ui = new ui_MainWidow();
ui->setupUI(this );
}
OlMainWindow::~OlMainWindow() {
//delete ui;
}
void OlMainWindow::enterUsername() {
std::cout << "Please, enter Username: " ;
std::getline(std::cin, _Username);
std::cout << "You'v accessed Username: " << _Username << std::endl;
}
FILE main.cpp
#include "olmainwindow.h"
#include <iostream>
int main(int argc, char * argv[])
{
OlMainWindow* w = new OlMainWindow();
return 0;
}
Last edited on Feb 21, 2020 at 7:20am UTC
Feb 21, 2020 at 7:59am UTC
You need to move the definition of setupUI(...) to the appropriate .cpp. You cannot use any member of a class that is just a forward reference.
Feb 21, 2020 at 10:21pm UTC
@coder777 thank you so much,
Topic archived. No new replies allowed.