美文网首页
44 - const Objects

44 - const Objects

作者: 社交帐号直接注册 | 来源:发表于2018-01-02 19:27 被阅读0次
    1. main.cpp
    #include <iostream>
    #include "Sally.h"
    using namespace std;
    
    int main()
    {
        int x = 3;
        cout << x << endl;
        Sally sal;
        sal.printShiz();
        const Sally sal2;
        sal2.printShiz2();
        return 0;
    }
    

    2.Sally.h

    ifndef SALLY_H

    define SALLY_H

    class Sally
    {
    public:
    Sally();
    void printShiz();
    void printShiz2() const;
    protected:
    private:
    };

    endif // SALLY_H

    3.Sally.cpp
    

    include "Sally.h"

    include <iostream>

    using namespace std;

    Sally::Sally()
    {
    }

    void Sally::printShiz()
    {
    cout << "first" << endl;
    }

    void Sally::printShiz2() const
    {
    cout << "second" << endl;
    }

    相关文章

      网友评论

          本文标题:44 - const Objects

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