Hello,
So I'm having trouble figuring out what the correct syntax is for a function with a return type that is a template type and is within a namespace. Anyone see anything wrong with the code below?
-------.HPP file:
#pragma once
#ifndef EC_UTIL_H
#define EC_UTIL_H
#include "../CommonHeaders.hpp"
#include "../core/common/APVertex.hpp"
#include <QString>
class QWidget;
namespace EditorCommon
{
template <class T> T *findAndAssert(QString id, QWidget *root);
}
#endif
#include "ECUtil.hpp"
------------------- .CPP file:
#include <QApplication>
#include <QWidget>
#include <QMessageBox>
namespace EditorCommon
{
template <class T> T *findAndAssert(QString id, QWidget *root)
{
T *w = root->findChild<T *>(id);
if(!w)
{
QMessageBox::critical(root , QString("Critical Application Error"), QString("Missing UI element: ") + id);
exit(EXIT_FAILURE);
}
return w;
}
}
------- In use:
mColumn.mEnableSnap = (QCheckBox *) findAndAssert<QWidget>(QString("uiEnableSnap"), panel);
------ Error:
WorkspaceDelegate.cpp:(.text+0x141): undefined reference to `QWidget* EditorCommon::findAndAssert<QWidget>(QString, QWidget*)'