1. Direct answer
If the class can be assigned / copied, you can simply write
QFile file;
int main()
{
file = QFile("C:\\example");
}
2. Use indirect actions
If not, you will have to resort to other parameters:
QFile* file = 0;
int main()
{
file = new QFile("C:\\example");
delete file;
}
Or use the boost::optional<QFile>, std::shared_ptr<QFile>, boost::scoped_ptr<QFile>etc.
3. Use singleton patterns:
Because of Fiasco's Static Initialization, you can write a function like this:
static QFile& getFile()
{
static QFile s_file("C:\\example");
return s_file;
}
++ 11 โโ- ( ++ 0x n3242, ยง6.7:)
