当前位置: 首页 > news >正文

网站建设前端tom企业邮箱注册

网站建设前端,tom企业邮箱注册,想象力做网站,优化方案英语选择性必修二答案demo1只有类的情况下调用 下面写一个util.h 文件里面 // 定义宏防止编译器重复编译 #ifndef TEST_H #define TEST_H class Test{ public:void sum(int a, int b);int num(int a, int b);bool number();}; #endif // TEST_H 调用的时候首先要引入这个头文件 #include "u…

demo1只有类的情况下调用

下面写一个util.h 文件里面

// 定义宏防止编译器重复编译
#ifndef TEST_H
#define TEST_H
class Test{
public:void sum(int a, int b);int num(int a, int b);bool number();};
#endif // TEST_H

调用的时候首先要引入这个头文件 #include "util.h"

cpp 里面实现

#include <iostream>
#include <string>
#include "util.h"
using namespace std;// 实现Test类的sum成员函数
void Test::sum(int a,int b){cout << "The sum of " << a << " and " << b << " is: " << a + b << std::endl;
}
// 实现Test类的num成员函数
int Test::num(int a, int b) {return a * b;
}
// 实现Test类的number成员函数
bool Test::number() {return true;
}int main() {int a =3;int b =6;Test test;test.sum(a,b);int result = test.num(a,b);cout<< "num result" << result <<endl;bool isNumber = test.number();cout<< "number result" << isNumber <<endl;return 0;
}

demo2 有namespace的情况下调用

util.h 文件

// 定义宏防止编译器重复编译
#ifndef TEST_H
#define TEST_H
namespace common::comm::com {
class Test{
public:void sum(int a, int b);int num(int a, int b);bool number();};
}
#endif  

cpp 里面实现,这里不使用using namespace

#include <iostream>
#include <string>
#include "util.h"
using namespace std;// 实现Test类的sum成员函数
void common::comm::com::Test::sum(int a,int b){cout << "The sum of " << a << " and " << b << " is: " << a + b << std::endl;
}
// 实现Test类的num成员函数
int common::comm::com::Test::num(int a, int b) {return a * b;
}
// 实现Test类的number成员函数
bool common::comm::com::Test::number() {return true;
}int main() {int a =3;int b =6;common::comm::com::Test test;test.sum(a,b);int result = test.num(a,b);cout<< "num result" << result <<endl;bool isNumber = test.number();cout<< "number result" << isNumber <<endl;return 0;
}

使用using namespace

namespace common::comm::com {
// 实现Test类的sum成员函数
void Test::sum(int a,int b){cout << "The sum of " << a << " and " << b << " is: " << a + b << std::endl;
}
// 实现Test类的num成员函数
int Test::num(int a, int b) {return a * b;
}
// 实现Test类的number成员函数
bool Test::number() {return true;
}
}
int main() {int a =3;int b =6;using namespace common::comm::com;Test test;test.sum(a,b);int result = test.num(a,b);cout<< "num result" << result <<endl;bool isNumber = test.number();cout<< "number result" << isNumber <<endl;return 0;
}

实际用不用,根据个人习惯即可,不使用using namespace在每次调用时都写出完整的命名空间路径

把util.h 文件修改一层一层的

// 定义宏防止编译器重复编译
#ifndef TEST_H
#define TEST_H
namespace common{namespace comm{namespace com{class Test{public:void sum(int a, int b);int num(int a, int b);bool number();};}}
}
#endif  

实现里面的方法效果也是一样的

#include <iostream>
#include <string>
#include "util.h"
using namespace std;namespace common::comm::com {
// 实现Test类的sum成员函数
void Test::sum(int a,int b){cout << "The sum of " << a << " and " << b << " is: " << a + b << std::endl;
}
// 实现Test类的num成员函数
int Test::num(int a, int b) {return a * b;
}
// 实现Test类的number成员函数
bool Test::number() {return true;
}
}
int main() {int a =3;int b =6;using namespace common::comm::com;Test test;test.sum(a,b);int result = test.num(a,b);cout<< "num result" << result <<endl;bool isNumber = test.number();cout<< "number result" << isNumber <<endl;return 0;
}

或者

#include <iostream>
#include <string>
#include "util.h"
using namespace std;namespace common {namespace comm {namespace com {// 实现Test类的sum成员函数void Test::sum(int a, int b) {std::cout << "The sum of " << a << " and " << b << " is: " << a + b << std::endl;}int Test::num(int a, int b) {return a * b;}bool Test::number() {return true; // 示例返回true}} // 结束命名空间 com} // 结束命名空间 comm
} // 结束命名空间 common
int main() {int a =3;int b =6;using namespace common::comm::com;Test test;test.sum(a,b);int result = test.num(a,b);cout<< "num result" << result <<endl;bool isNumber = test.number();cout<< "number result" << isNumber <<endl;return 0;
}

http://www.yayakq.cn/news/455282/

相关文章:

  • 如何做php网站建设用vs2008做网站教程
  • 外贸网站设计风格沈阳网站建设开发
  • 网站不备案访问做网站推广的工作内容
  • 乐器销售网站模板在线logo制作免费
  • 网站服务器繁忙是怎么回事外贸仿牌网站建设
  • php网站打开慢英雄联盟网页设计代码
  • 2o18江苏建设网站施工员模试卷百度邮箱注册申请免费注册
  • 安徽教育云平台网站建设wordpress 博客搬家
  • 比较好的建站系统企业门户网站登录
  • 大型门户网站建设定做兰州建设厅网站
  • 河南5G网站基站建设信息做花型设计哪个网站下载素材好
  • 深圳网站建设服务网站开发工具有组合
  • wap免费网站百度推广和哪些网站有合作
  • 如何制作官方网站电子公司网站源码
  • 网站建设公司一般用什么建站系统上辽宁建设工程信息网站
  • 免费网站制作教程做照片有那些网站好
  • 手怎么搭建网站搭建网站需要学什么软件
  • 个人做淘宝客网站要备案江阴青阳道路建设网站
  • 怎么建设大淘客网站凡客现在官网都找不到了
  • 能够做一镜到底的网站辽宁建设厅官网
  • 邯郸网站设计多少钱推广运营怎么做
  • 扎金花网站怎么做做网站什么框架方便
  • 做搜狗手机网站快佛山网站建设拓客科技
  • 广州网站开发定制黄岛建设厅官方网站
  • 开封公司做网站业务系统管理软件
  • 专业手机网站开发产品包装设计网
  • 搭建本地网站做色流什么网站做调查能赚钱吗
  • 张家港英文网站制作网络科技公司起名免费
  • 济南建站公司价格上海网站建设推广
  • 门户网站需要多大的服务器品牌建设和市场营销的区别