Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the type of a class name follow by parenthesis

I can't understand such syntax in https://github.com/hmenke/boost_matheval/blob/master/src/qi/parser.hpp#L43

struct bar {
    bar() {}
};

template<typename _T>
class foo {
public:
    foo() {}
};

...
foo<bar()> fb;
...

What is the type of _T in the specialization of the templates foo? How to use _T in foo?

like image 731
Devymex Avatar asked Jan 02 '20 05:01

Devymex


People also ask

Can a class have parentheses?

Classes have parenthesis because when initially called you're most likely looking to execute the creation of a new object of that class. Methods will have parenthesis because once created they're meant to be called. I hope this helps.

What are parentheses used for in Java?

{} are used to define a dictionary in a "list" called a literal parentheses in java: Parentheses are used for two purposes: (1) to control the order of operations in an expression, and (2) to supply parameters to a constructor or method. ................. and many more in simple: A parenthesis is a punctuation mark ...

Do classes need parentheses in Python?

class C: Function/method definitions always take parentheses, even if you don't define parameters. If you don't use them, you'll get a SyntaxError. Later, after the definition of a class/function/method in the code, just writing the name will point you to the class/function/method.

Are specified after the method name in a class inside parentheses?

Parameters and Arguments Parameters are specified after the method name, inside the parentheses.


1 Answers

It's the type of a function. When you declare

bar function();

I.e., a function taking no arguments and returning a bar, then function has a type, and it's bar(). _T stands for it. As though you have an alias

using _T = bar();

or

typedef bar _T();

It's not an uncommon type to see. For instance, function types are what std::function accepts. How to use it depends on the purpose of the class template, and how it's potentially specialized.

like image 98
StoryTeller - Unslander Monica Avatar answered Nov 14 '22 22:11

StoryTeller - Unslander Monica