I've never seen this syntax before. What is it?

Hey all.
I have not done much C++ in the past 20 years or so. A lot has changed since my college days.

I ran across some C++ syntax today that I was not able to figure out. Not even sure what it's called. So, I'm hoping that someone might be able to explain to me what it is, or at least point me in the right direction where I can read up on it....

Here is the code.

1
2
3
4
5
6
7
8
9
// Define and parse command-line arguments.
CmdParserCommon cmdparser(argc, argv);

CmdOption<bool> reverse_sort(cmdparser,0,"reverse-sort","","performs descending
                             sort (default is ascending).",false);

CmdOption<int> array_size(cmdparser,'s',"size","<integer>","input/output array
                          size.",33554432);
cmdparser.parse();


What exactly is CmdOption<bool> and CmdOption<int>

They look like return types, but, are they? There are not return variables being defined. Resembles a function declaration, yet it's not.

Are they some kind of function attributes?

I had a friend who knows a lot more about C++ than I do, he was kind of stumped as well.

Hoping someone can shed some light on this C++ wizardry. :D
Last edited on
There's nothing really unusual about those lines, assuming they're in a function scope.

Lines 4 and 5 construct a local object named 'reverse_sort' of type 'CmdOption<bool>', while passing to the constructor the following parameters:
* cmdparser
* 0
* "reverse-sort"
* ""
* "performs descending sort (default is ascending)."
* false

Lines 7 and 8 construct a local object named 'array_size' of type 'CmdOption<int>', while passing to the constructor the following parameters:
* cmdparser
* 's'
* "size"
* "<integer>"
* "input/output array size."
* 33554432

It's just your typical object construction syntax.
 
type identifier(constructor_parameter_list);
Last edited on
Yep, ok... I feel dumb now. I've done C# for so long that I've forgotten some of the C++ basics, the differences between object construction in C# and C++.

I went and looked at the class definition and it makes since now.

Thanks for the help!
Topic archived. No new replies allowed.