2004.03.17 10:51:41 (*.67.216.254)
587
16 / 0
undefined
#include<iostream.h>

class base{
        int i;
public:
        base();                                //기본 생성자
        base(int n);                //매개변수 생성자
        void show_i();                //멤버함수
        ~base();                        //소멸자


};
base::base()
{
        i=10;
        cout<<"base 클래스 기본생성자\n";
}
base::base(int n)
{
        i=n;
        cout<<"base 클래스 매개변수 생성자"<<endl;
}
void base::show_i()
{
        cout<<"base 의 i = "<<i<<endl;
}
base::~base()
{
        cout<<"base 의 소멸자 호출 "<<endl;
}
class child : public base
{
        int j;
public:
        child();                        //기본생성자
        child(int n);                //매개변수 생성자
        void show_j();                //멤버함수
        ~child();                        //소멸자
};
child::child()
{
        j=100;
        cout<<"child 클래스 기본생성자\n";
}
child::child(int n)
{
        j=n;
        cout<<"child 매개변수 생성자\n";
}
void child::show_j()
{
        cout<<"child 의 j = "<<j<<endl;
}
child::~child()
{
        cout<<"child 소멸자 호출"<<endl;
}
int main()
{
        child ob1;
        child ob2(20);
        ob1.show_i();
        ob2.show_i();
        ob1.show_j();
        ob2.show_j();

        
        
        return 0;
}


 


 

내가 듣고싶은 음악
내가 들려주고싶은 음악

2004.03.17 10:24:48 (*.67.216.254)
753
16 / 0
undefined
#include<iostream.h>
class Myclass{
        int a;
public:
        Myclass();                //기본생성자 아래는 매개변수를 갖는 
        Myclass(int x);        //객체 생성시에 바로 호출
        void show();
        ~Myclass(); // 끝날때 자동호출 
};
Myclass::Myclass()
{
        cout<<"기본생성자 호출"<<endl;
        a=10;
}

Myclass::Myclass(int x)  // 메인에서 받아옴 
{
        cout<<"매개변수 생성자 호출 \n";
        a=x;
}
Myclass::~Myclass()
{
        cout<<"Destructing...\n";
}
void Myclass::show()
{
        cout<<a<<endl;
}
int main()
{
        Myclass ob1; //객체 생성 
        Myclass ob2(4); //객체 생성 
        ob1.show();
        ob2.show();
        return 0;
}



내가 듣고싶은 음악
내가 들려주고싶은 음악

Category
Category
Blog (233)
Bottom
Category
Calendar
2010.09
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
Bottom
Category
Recent Article
Bottom
Category
Recent Comment
Bottom
Category
Counter
Bottom