Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

expected identifier before 'this'?

30 views
Skip to first unread message

Heinz-Mario Frühbeis

unread,
May 2, 2016, 2:48:00 AM5/2/16
to
Hi,

here I'm using a class within a class, or better, I want to use a class
within a class in this way:

class Test{
private:
class Test1{
public:
Test *mTest;
Test1(Test *vTest){
mTest = vTest;
}
};
Test1 mTest1(this); // <--- here is this error
};

One explanation is:
expected identifier before 'this'
And another is:
expected ',' or '...' before 'this'

And to get me a little more confused..., this is compiling:
class Test{
private:
class Test1{
public:
Test *mTest;
Test1(Test *vTest){
mTest = vTest;
}
};
Test1 mTest1(); // <--- no error anymore?
};


What is wrong? What is right?

Regards
Heinz-Mario Frühbeis

Ian Collins

unread,
May 2, 2016, 3:21:52 AM5/2/16
to
On 05/02/16 18:47, Heinz-Mario Frühbeis wrote:
> Hi,
>
> here I'm using a class within a class, or better, I want to use a class
> within a class in this way:
>
> class Test{
> private:
> class Test1{
> public:
> Test *mTest;
> Test1(Test *vTest){
> mTest = vTest;
> }
> };
> Test1 mTest1(this); // <--- here is this error

To initialise a non static member, that would have to be

Test1 mTest1 {this};

--
Ian Collins

Heinz-Mario Frühbeis

unread,
May 2, 2016, 3:59:53 AM5/2/16
to
This is compiling, thank you, thank you very much!

But, this is raising warnings and (naturally) another issue:

/media/.../ida_login/c_idasection.h:163: Warnung: non-static data member
initializers only available with -std=c++11 or -std=gnu++11 [enabled by
default]
c_Areas mAreas{this};
^

/media/.../ida_login/c_idasection.h:163: Warnung: extended initializer
lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
c_Areas mAreas{this};
^

Here, I'm using QT Creator 3.0.1 Based on QT 5.2.1 (from my About dialog).

And on this site
<http://stackoverflow.com/questions/16948382/how-to-enable-c11-in-qt-creator>
I can read 'use CONFIG += c++11', but that isn't working for me...

But ok so far, thanks again and
with ragards
Heinz-Mario Frühbeis

Reinhardt Behm

unread,
May 2, 2016, 4:11:30 AM5/2/16
to
Heinz-Mario Frühbeis wrote:

> Here, I'm using QT Creator 3.0.1 Based on QT 5.2.1 (from my About dialog).
>
> And on this site
> <http://stackoverflow.com/questions/16948382/how-to-enable-c11-in-qt-
creator>
> I can read 'use CONFIG += c++11', but that isn't working for me...

Your qmake seems to be too old for this.
Use instead or something similar:

QMAKE_CXXFLAGS += -std=gnu++11
.

--
Reinhardt

Heinz-Mario Frühbeis

unread,
May 2, 2016, 7:02:10 AM5/2/16
to
No, sir, its not working.

What is working is, if I declare as 'new':
Test1 *mTest1;
And e.g. in the constructor-function:
this->mTest1 = new Test1(this);
...

But thanks.
Regards
Heinz-Mario Frühbeis

Heinz-Mario Frühbeis

unread,
May 2, 2016, 7:25:54 AM5/2/16
to
Am 02.05.2016 um 13:01 schrieb Heinz-Mario Frühbeis:
> Am 02.05.2016 um 10:11 schrieb Reinhardt Behm:
>> Heinz-Mario Frühbeis wrote:
>>
>>> Here, I'm using QT Creator 3.0.1 Based on QT 5.2.1 (from my About
>>> dialog).
>>>
>>> And on this site
>>> <http://stackoverflow.com/questions/16948382/how-to-enable-c11-in-qt-
>> creator>
>>> I can read 'use CONFIG += c++11', but that isn't working for me...
>>
>> Your qmake seems to be too old for this.
>> Use instead or something similar:
>>
>> QMAKE_CXXFLAGS += -std=gnu++11
>> .

BREAK BREAK BREAK - TIMEOUT :)

Oh, man, I wrote Test1 mTest1(this);, instead of Test1 mTest1{this};.

Exuse me, sir! So, yes, it is working now!

Thank you very much, sir.
Regards
Heinz-Mario Frühbeis

0 new messages