Home What is this weird colon-member (" : ") syntax in the constructor?

# What is this weird colon-member (" : ") syntax in the constructor?

user668
1#
user668 Published in March 18, 2018, 5:09 pm
 Recently I've seen an example like the following: #include class Foo { public: int bar; Foo(int num): bar(num) {}; }; int main(void) { std::cout << Foo(42).bar << std::endl; return 0; }  What does this strange : bar(num) mean? It somehow seems to initialize the member variable but I've never seen this syntax before. It looks like a function/constructor call but for an int? Makes no sense for me. Perhaps someone could enlighten me. And, by the way, are there any other esoteric language features like this, you'll never find in a ordinary C++ book?
 You need to login account before you can post.
Processed in 0.425718 second(s) , Gzip On .