第三章類

1410 ワード

クラスクラスクラス


同じメンバーがいますが、メモリが異なります.

構造体のメンバー関数structまたはclass


このメンバーは、classデフォルトがプライベートであればstructデフォルトが共有されます.
struct person//// class person
{
private:
    int id;
    int money;
public:
    void show()
    {
        cout<

クラスドメイン

class person
{

    int id;
    int money;
public:
    void show();/// 
    void set(int a,int b);
};
void person:: show()// person::
{
    cout<

メイン関数とサブ関数をカプセル化


しゅかんすう
#include
#include"person.h"
using namespace std;

int main (int argc,char** argv)/// 
{
    struct person a;
    struct person b;
    a.set(1,1000);
    a.show();
}

サブ関数
#include"person.h"
#include
void person:: show()
{
    cout<

hファイル
using namespace std;
class person
{

    int id;
    int money;
public:
    void show();/// 
    void set(int a,int b);
};

役割ドメインの相互関係

class person
{

public:
    void show();
    void set(int a,int b);
};
class test 
{
    public: 
    void show();
};
void test::show()
{
    cout<

どのようにclassの中の関数にパラメータを伝達します

class test 
{
    int id;// , 

public: 
    void set(int i){id=i;}
    void show(){
                    cout<