How does the compiler know how obj
looks like? It is not included in form.h
, but it works anyway.
form.h
#ifndef FORM_H
#define FORM_H
template <class T>
class Form
{
public:
Form(T* obj) {}
};
#endif // FORM_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
form = new Form<MainWindow>(this);
}
MainWindow::~MainWindow()
{
delete ui;
}