struct Bracket {
Bracket(char type, int position):
type(type),
position(position)
{}
bool Matchc(char c) {
if (type == '[' && c == ']')
return true;
if (type == '{' && c == '}')
return true;
if (type == '(' && c == ')')
return true;
return false;
}
char type;
int position;
};
Asked
Active
Viewed 42 times
0

Adrian Mole
- 49,934
- 160
- 51
- 83
-
1It initializes member variables with arguments. What exactly you don't understand? – Daniel Langr Aug 16 '20 at 14:08
-
And it can be done with both curly brackets as parenthesis: `Bracket(char type, int position): type{type}, position{position} {}`. – Aug 16 '20 at 14:09
-
Possibly relevant question: [Initializing member variables using the same name for constructor arguments as for the member variables allowed by the C++ standard?](https://stackoverflow.com/q/6185020/580083). – Daniel Langr Aug 16 '20 at 14:10
-
You can think about it as `Bracket(char in_type, int in_position) : type(in_type), position(in_position) {}`. It initialises the member variables `type` and `position` of `Bracket` – Ody Aug 16 '20 at 14:14
-
Are you confused that this is a `struct` instead of a `class`? I ask because the member initialization list should be covered when classes are introduced in any `c++` text book. What may not be covered is that a `struct` is the same as a `class` but instead of it defaults to public instead of private. Related: [https://stackoverflow.com/a/999810/487892](https://stackoverflow.com/a/999810/487892) – drescherjm Aug 16 '20 at 14:14