45 - Member Initializers

2018-01-02  本文已影响0人  社交帐号直接注册
#include <iostream>
#include "Sally.h"
using namespace std;

int main()
{
    Sally so(3,87);
    so.print();
    return 0;
}
#ifndef SALLY_H
#define SALLY_H

class Sally
{
public:
    Sally(int a,int b);
    void print();
protected:
private:
    int regVar;
    const int constVar;
};

#endif // SALLY_H
#include "Sally.h"
#include <iostream>
using namespace std;

Sally::Sally(int a,int b):regVar(a),constVar(b)
{

}

void Sally::print()
{
    cout << "first  " << regVar << "  second  " << constVar << endl;
}
上一篇 下一篇

猜你喜欢

热点阅读