"T var ();" always declaring a function in C ++?

Could this be an instantiation (definition) in some cases?

+3
source share
2 answers

This is always a function declaration in C ++ (and in C), unless it appears as a parameter declaration, in which case it declares a pointer to the function.

The converse cannot be indicated:

Is "T var"? always declare an object in C ++?

No, this is not so, because it Tcan be a type of function, in which case it varwill be declared as a function, except when it appears as a parameter declaration, as indicated above.

+3
source

"T var();" ++?

.

1:

template<typename T> 
void func()
{
    T var(); // function declaration
}

2:

template<typename T>
void func(T var() ) // equivalent to `template<typename T> void func (T()) { } `
{
}

func void , T. var .


T var(1);, , T var = T(1);

T var(1) , T var = T(1) . var T (1).

T - , , - .

0

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


All Articles