제1 2 주 임무 2 (기본 구성원 의 방문 한정 부적 과 파생 류 의 계승 방식 이해)

/* (        ) 
*              
* Copyright (c) 2011,             
* All rights reserved. 
*     :    
*    : 
*     : 2012   5   7   
*      : 

*               
*     : 
*     :                  ,                  
*     : 
*           
#include<iostream>
#include<string>
using namespace std;
class Student //(1)  student                  ,        
{public: 
	Student(int n,string nam,char s) ;
	void show();
	~Student( ){ } 
 protected: //   private   Student::sex”:      private   
	int num;
	string name;
	char sex ; 
};

class Student1: public Student //  protected “Student::show”    ,  “Student1”  “protected” “Student”  
{ public: 
Student1(int n,string nam,char s,int a,string ad);
	void show1( );
	~Student1( ){ } 
 private: 
	int age; 
	string addr; 
};

Student::Student(int n,string nam,char s) 
{	num=n;
	name=nam;
	sex=s; 
}
void Student::show()
{	cout<<"num: "<<num<<endl;
	cout<<"name: "<<name<<endl;
	cout<<"sex: "<<sex<<endl<<endl;
}

Student1:: Student1(int n,string nam,char s,int a,string ad):Student(n,nam,s) 
{     age=a; 
	  addr=ad;
}
void Student1::show1( )
{	cout<<"num: "<<num<<endl;
	cout<<"name: "<<name<<endl;
	cout<<"sex: "<<sex<<endl;
	cout<<"age: "<<age<<endl;
	cout<<"address: "<<addr<<endl<<endl;
}

int main( )
{	Student1 stud1(10010,"Wang-li",'f',19,"115 Beijing Road,Shanghai");
	Student1 stud2(10011,"Zhang-fun",'m',21,"213 Shanghai Road,Beijing");
	Student stud3(20010,"He-xin",'m');
	stud1.show1( ); 
	stud2.show( ); 
	stud3.show( ); 
	system("pause");
	return 0;
}
  :   : 
 Student          ,         :error C2248: “Student::num”:      private   ( “Student”    ) 
                        ,       ,        
   : 
       protected,         : error C2247: “Student::show”    ,  “Student1”  “protected” “Student”   
                      
   : 
       private,         : error C2247: “Student::show”    ,  “Student1”  “private” “Student”   
                    ,          ! 
  :1.                     ,        
2.                      ,       
3.       ,              , 
    ,        ,         
   ,        ,          
     ,           


좋은 웹페이지 즐겨찾기