Go Class declaration as param template. Why does it work?

I played with some meta programming of the C ++ template, and I discovered a situation which, in my opinion, is rather strange. Say I have the following class.

template<typename T>
class Foo{
};

Then later I discovered that I was using the foward declaration for the class (I assume this is what it refers to) as an argument to the template as such

Foo<class bar> bar1;

I also found that the following also compiles.

Foo<class bar()> bar2;
Foo<class bar(int a)> bar3;

So my question is: why does this work. What happens in all three cases.
According to the standard, I cannot declare a class at this point, so this fails:

Foo<class bar{}> bar4

, , ( , , ). . , : ? - , ++ , . , , .

g++

+4
2

bar, .


Foo<class bar> bar1;

, , ..

class bar;
Foo<bar> bar1;

Foo<class bar()> bar2;

bar, , , bar.


Foo<class bar(int a)> bar3;

, , int, none.

class bar;
Foo<bar(int)> bar3;
+5

Foo< ... >. , , " " (bar ), , T .

++ class bar bar C, struct bar, , struct bar { ... };. ++ struct/class , , bar .

class bar() class bar(int a) - . bar () bar (int) , .. ( / a int), a bar.

0

Source: https://habr.com/ru/post/1653359/


All Articles