类class

类和成员函数(类外定义与类内定义)

#include <bits/stdc++.h>

using namespace std;

class student {
public:
    int name = 453;
    string c = "ASFASDF";

    void display() {
        cout << name << endl;
        cout << c;
    }

    int max(int a);

} stu1;

int student::max(int a) {
    cout << a + 3 << endl;
}

inline int en(int a) {
    return 1;
}

int main() {
    stu1.display();
    cout << en(4)<<endl;
    cout<<stu1.max(stu1.name);
    return 0;
}

含有构造函数的类声明,以及定义类对象的注意事项

#include <iostream>
#include <string>

using namespace std;
struct student {
    int name = 44;
};

string en(const std::string  a) {
    return a;
}

class stu {
public:
    int id;
    int num;
    string a;
    stu(int , int,string );
};
//含有构造参数的类不能在结束末尾直接定义 

//class stu {
//public:
//    int id;
//    int num;
//    string a;
//    stu(int , int,string );
//}s1;         错的
stu::stu(int x, int  y,string z) {
    id = x;
    num = y;
    a=z;
}

int main() {
    const string c = "sdafsa";
    stu s1 (12, 45, "fdsaf");
    cout << en(c)<<s1.id;
    return 0;
}
全部评论

相关推荐

07-07 11:33
江南大学 Java
已经在暑假实习了&nbsp;,没有明确说有hc,纠结实习到八月份会不会有点影响秋招毕竟感觉今年好多提前批
程序员小白条:92的话准备提前批,其他没必要,没面试机会的,而且你要准备充分,尤其八股和算法题
点赞 评论 收藏
分享
人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 12:05
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务