question of structured data
I can understand the first row and last two rows.
However, does anyone know what the remaining part means ????(line3-line16)
especially for line3-line5
1 struct Bracket
2 {
3 Bracket(char type, int position):
4 type(type),
5 position(position)
6 {}
7 bool Matchc(char c)
8 {
9 if (type == '[' && c == ']')
10 return true;
11 if (type == '{' && c == '}')
12 return true;
13 if (type == '(' && c == ')')
14 return true;
15 return false;
16 }
17 char type;
18 int position;
19 };
Re: question of structured data
line 3 defines the struct constructor (think of class - struct is class with all public by default).
line 4, 5 initialises the struct variable type to the value of the parameter type. Same with position.
lines 7 - 16 is a struct member function Matchc() which uses the value of the member variable type as part of its condition tests. Note that Matchc() can be simplifed to
Code:
bool Matchc(char c)
{
return (type== '[' && c == ']') || (type == '{' && c == '}') || (type == '(' && c == ')');
}
Re: question of structured data
Thank you.
I think I need to learn something about constructor. I didn't know that before.
Re: question of structured data
constructors are part of c++ OOP and are usually used with class (although can be used with struct). See http://www.learncpp.com/cpp-tutorial...d-programming/
In c++ OOP, there is really no difference between a class and a struct. The only difference is that for struct all members are default public whilst with class all members are private by default.
Re: question of structured data
Quote:
Originally Posted by
2kaud
In c++ OOP, there is really no difference between a class and a struct. The only difference is that for struct all members are default public whilst with class all members are private by default.
There's a second difference that's of importance in OOP: Classes have private inheritance by default while structs have public.