类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;
}
全部评论

相关推荐

06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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