class A
{
pointer* p;
template<class T> f(T a)
{
p->property()->doSomething(a); // doSomething is a template function
}
};
Above won’t compile, but I want to access the member pointer in the template function even though it’s unsafe. The reason I want to do this is because ‘p->property()->doSomething(a)’ is actually really really long, and I’m tried of rewriting it (and I don’t want to use #define). So, how do I do something like that?
Edit: doSomething is a 3rd party function… but I think it is something like this:
template<class T>
void doSomething(T a)
{
// something
}
Edit: here’s the actual code:
#include <QMainWindow>
#include <QtNetwork>
#include <QtWebKit>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void replyFinished(QNetworkReply*);
private:
Ui::MainWindow *ui;
QNetworkAccessManager *nam;
QUrl _url;
void outputHeader(QNetworkReply*);
template<class T> void writeToOuput(T arg)
{
ui->textEdit->append(QString("%1").arg(arg));
}
};
Edit: Here’s the error I’m getting: ‘invalid use of incomplete type ui::MainWindow’
When I click it, it goes to this line ‘ui->textEdit->append(QString(“%1”).arg(arg));’ in the code
Edit: Here’s the other error: ‘Forward declaration of Ui::MainWindow’
When I click it, it goes no where.
With the way the question is worded as is right now, I’m really having trouble making out what the problem is. However, if this is the code giving you trouble:
<QTextEdit>Ui::MainWindowactually define a member calledtextEdit?It’d help if you could post the build error.
And finally, just a suggestion, but I’d recommend moving this to your cpp file as a non-member function:
Rationale:
Update: op posted the error.
You need to include the header that defines ui::MainWindow instead of just working with a forward declaration. For MOC-generated files like this, that’s generally going to be called ui_MainWindow.h.