Amis C ++, constantes, membres statiques

// Fichier d'en-tête 
#ifndef STUDENT_H 
#define STUDENT_H class Student 
{ public : 
    friend void Print_Student ();   // Friend declaration 
    Student ( const int m_student_id, const char * m_student_name); // Construire 
    Student avec des paramètres ( const Student & other); // Copie de la construction privée :
     void printStudentInfo (); // Sortie des informations sur l'élève void SetStudentName ( const char * m_student_name); // Définition du nom de l'élève


  

     
    static  int School_Id; // définir l'id de l'école 
    const  int StudentId;    // définir l'id de l'élève 
    char * StudentName; // définir le nom de l'étudiant 
};
 int Student :: School_Id = 1 ; // les membres statiques de la classe doivent être initialisés en dehors de la classe 

void Print_Student (); 


#endif

// fichier cpp

#define _CRT_SECURE_NO_WARNINGS 
#include <iostream> 
#include " Student.h " 
using  namespace std;
// 带 参 构造 
Student :: Student ( int m_student_id, const  char * m_student_name): StudentId (m_student_id) 
{ 
    this -> StudentName = new  char [strlen (m_student_name) + 1 ]; 
    strcpy ( this -> StudentName, m_student_name); 
} 
// 拷贝 构造 
Student :: Student ( const Student &AUTRES): StudentID (other.StudentId) 
{ 
    la présente -> StudentName = new new  omble [strlen (other.StudentName) + . 1 ]; 
    strcpy ( le présent -> StudentName, other.StudentName); 
} 
// imprimer les informations de l' étudiant 
vide étudiant :: printStudentInfo () 
{ 
    cout << " School id: " << School_Id << " \ tStudent ID: " << StudentId << " \ tStudent name: " << StudentName << endl; 
} 
// Définir l'élève Nom 
void Student ::SetStudentName ( const omble chevalier * m_student_name) 
{ 
    strcpy ( le présent -> StudentName, m_student_name); 
} 
vide Print_Student () 
{ 
    Student temp1 ( 1 , " Bob " );     
    temp1.printStudentInfo ();    // information des étudiants d'impression 1 
    temp1.SetStudentName ( " Petit Juste " ); 

    Student temp2 (temp1); 
    temp2.printStudentInfo (); // Imprimer les informations de l'étudiant 2 
} 

int main () 
{ 
    Print_Student (); 
    return  0 ; 
}

 

Je suppose que tu aimes

Origine www.cnblogs.com/shenji/p/12680528.html
conseillé
Classement