美文网首页
45 - Member Initializers

45 - Member Initializers

作者: 社交帐号直接注册 | 来源:发表于2018-01-02 19:37 被阅读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;
}

相关文章

网友评论

      本文标题:45 - Member Initializers

      本文链接:https://www.haomeiwen.com/subject/frmqnxtx.html