Bug #2822
closedC2027: use of undefined type 'Wt::WContainerWidget'
0%
Description
(followup to #2820)
with MS VC Express 2012
P:\sand\wt-starter\1-hello\hello.C:26: error: C2027: use of undefined type 'Wt::WContainerWidget'
P:\Wt3.3.1-vc2012\include\Wt\WGlobal:49: see declaration of 'Wt::WContainerWidget'
P:\sand\wt-starter\1-hello\hello.C:26: error: C2227: left of '->addWidget' must point to class/struct/union/generic type
You can reproduce with:
#include <Wt/WApplication>
#include <Wt/WText>
//#include <Wt/WContainerWidget> //ISSUE: http://redmine.webtoolkit.eu/issues/2820
using Wt::WApplication;
using Wt::WEnvironment;
using Wt::WText;
using Wt::WRun;
class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env) : WApplication(env)
{
setTitle("Hello world");
root()->addWidget(new WText("Hello World"));
}
static WApplication* create(const WEnvironment& env)
{
return new HelloApplication(env);
}
};
int main(int argc, char **argv)
{
return WRun(argc, argv, HelloApplication::create);
}
The above code must compile, without any forward declarations or additional include directives.
Updated by Emeric Poupon about 10 years ago
must? Not that sure,
You use the root() method which gives you a pointer to a Wt::WContainerWidget.
As Wt::WContainerWidget is forward declared by , you have to include the header yourself if you want to use it.
Updated by I. Lazaridis about 10 years ago
Emeric Poupon wrote:
must? Not that sure,
You use the root() method which gives you a pointer to a Wt::WContainerWidget.
As Wt::WContainerWidget is forward declared by , you have to include the header yourself if you want to use it.
Nonsense. "root()" is basic usage of the class WApplication, so yes, it must compile.
Updated by Wim Dumon about 10 years ago
- Status changed from New to Closed
This is how you can avoid including WContainer:
class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env) : WApplication(env)
{
setTitle("Hello world");
WText * mytext = new WText("Hello World", root());
}
static WApplication* create(const WEnvironment& env)
{
return new HelloApplication(env);
}
};
Updated by I. Lazaridis about 10 years ago
Wim Dumon wrote:
This is how you can avoid including WContainer:
[...]
Please, this is not the issue.
WContainerWidget is basic usage of WApplication, and should be included.
Forward-declarations should be limited to what is not basic usage of a class.
A simple hello world raises immediately the question: "why I have to include WContainerWidget, it's integral part of WApplication?"
If a non-measurable compile-time saving (once a year or so) is more important than usability and simplicity, then something is wrong with your priorities.
just thing of it.
(and btw: code in tutorials should show some things, not be as compact as possible, or avoid include directives.)
#include <Wt/WApplication>
#include <Wt/WText>
[...]
class HelloApplication : public WApplication
{
public:
HelloApplication(const WEnvironment& env) : WApplication(env)
{
setTitle("Hello world");
WContainerWidget* parent = this->root();
parent->addWidget(new WText("Hello World"));
}
static WApplication* create(const WEnvironment& env)
{
return new HelloApplication(env);
}
};