I was going through a very simple looking program, but as I am a newbie in C++ it created problem for me. I thought it will give compilation error but it went smoothly.
Expand|Select|Wrap|Line Numbers
- #include<iostream>
- using namespace std;
- class sample
- {
- int i;
- public:
- sample(int ii)
- {
- i=ii;
- }
- };
- class comp
- {
- sample s;
- public:
- comp(int ii) : s(10)
- {
- }
- };
- int main()
- {
- comp c(10);
- }
(1) In class comp object of class sample has been created but no corresponding constructor is in sample class,i.e., constructor with zero arguments, so this should create an error, but it doesn't.
(2) What is the meaning of : operator in comp(int ii) : s(10).
Please help me
thanx in advance.