I defined a class in a namespace in a header as follows
#ifndef _c1_
#define _c1_
namespace classspace
{
class Aclass;
}
class Aclass
{
//body
};
#endif _c1_
I added this header to main.cpp and made an object in main() but its returning error that undefined class 'classspace::Aclass'
its my main
void main()
{
classspace::Aclass b;
}
when I defined class as
class classspace::Aclass
{
//body
};
error resolved. I saw in Qt mainwindow file using first approach:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
is working without any error. what is my mistake in the first approach?
See Question&Answers more detail:os