|
-
December 24th, 2001, 04:44 AM
#1
Two points make the job done?! Why?
One of my fellow programer came into such a problem: how to initialize a class with two private variables contained in another class' constructor.
Why initialization in this way can get the job down?
Thanks in advance.
#include <iostream.h>
class B
{
public:
B(){};
B(int i, int j);
void printb();
private:
int a , b;
};
B::B(int i,int j)
{
a=i;
b=j;
}
void B: rintb()
{
cout<<"a="<<a<<",b="<<b<<endl;
}
class A
{
publcic:
A(){};
A(int i, int j);
void printa();
private:
B c;
};
A::A(int i,int j):c(i,j) // the special usage of initialization, private value of i and j can be initializated
{
}
void A: rinta()
{
c.printb();
}
void main()
{
A m(7,9);
m.printa();
}
VC++ developer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|