C++ 简单的编程问题Class
发布网友
发布时间:2022-05-29 18:08
我来回答
共4个回答
热心网友
时间:2023-11-01 02:25
#include "stdafx.h"
#include <iostream>
using namespace std;
namespace ZM
{
class YY
{
int a;
int b;
public:
void display(int x,int y);
void BB(void);
};
void display(int x,int y)
{
cin >> x;
cin >> y;
}
}
方法1: 添加using namespace zm;
using namespace ZM;
int main()
{
YY a;
a.display(10,20); //调用了函数
return 0;
}
方法2: 直接调用
int main()
{
ZM::YY a; //这么使用。在名字空间后加上“::”。
a.display(10,20);
return 0;
}
热心网友
时间:2023-11-01 02:26
呵呵,简单
#include <iostream>
using namespace std;
namespace STP
{
class Person
{
public:
Person(int x):x(x)
{
}
void getX()
{
cout << x << endl;
}
private:
int x;
int y;
};
}
int main()
{
STP::Person a(2);
a.getX();
return 0;
}
热心网友
时间:2023-11-01 02:26
int main()
{
ZM::YY app; //这不是 声明 类的 对象吗
app.display(10,20); // 调用 类 函数
}
就这样了。如此简单。
还要怎么说呢。。。。。。。 - -
热心网友
时间:2023-11-01 02:27
#define MAX=10
class jk
{
public:
int key,index;
}job[MAX];
bool co(Job p,Job q)
{
return p.key<=q.key;
}