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

企业网站 建设公司广东省最新新闻

企业网站 建设公司,广东省最新新闻,王爷太能作,写好网页怎么建成网站union的作用基本是它里面的变量都用了同一块内存&#xff0c;跟起了别名一样&#xff0c;类型不一样的别名。 基本用法&#xff1a; struct Union{union {float a;int b;};};Union u;u.a 2.0f;std::cout << u.a << "," << u.b << std::endl…

union的作用基本是它里面的变量都用了同一块内存,跟起了别名一样,类型不一样的别名。
基本用法:

	struct Union{union {float a;int b;};};Union u;u.a = 2.0f;std::cout << u.a << "," << u.b << std::endl;

常规用法,见结构体:

#include <iostream>
#include <string>
#include <vector> 
#include <algorithm> /* sort*/
#include <functional> /*std::greater<int>()*/
#include "game.h"struct Vector2 {float x, y;
};struct Vector4
{/*因使用union方法,故先注释掉*/// float x, y, z, w;//Vector2 GetA() { /*这样的方法将会创建一个新的对象,我们不想这么做*///	return Vector2(); //}/*一种方法*//*Vector2& GetA() {  return *(Vector2*)&x;}*//*但是如果使用Union的话可能就要好的多*/union {// float x, y, z, w; /*如果这么写的话是不行的,因为四个值用的同一块内存*//*解决办法是用结构体,这里union和struct都没有名字,他们都是匿名函数*/struct {float x, y, z, w;};/*这里再向union添加另一个结构体,显然他们是占用同一块内存的这里就体现了Union的用处*/struct {Vector2 a, b;};};
};void PrintVector2(const Vector2& vector2) {std::cout << vector2.x << " " << vector2.y << std::endl;
}int main() {Vector4 vector = { 1.0f, 2.0f, 3.0f, 4.0f };std::cout << vector.x << std::endl; /*可以看到,还是可以访问x的*/PrintVector2(vector.a);PrintVector2(vector.b);vector.z = 500.0f;PrintVector2(vector.a);PrintVector2(vector.b);struct Union{union {float a;int b;};};Union u;u.a = 2.0f;std::cout << u.a << "," << u.b << std::endl;/*测试game*/// game::runGame();std::cin.get();
}
http://www.wangmingla.cn/news/74469.html

相关文章:

  • 常州市网站优化seo研究中心南宁线下
  • 免费b站不收费长春seo排名收费
  • 农产品网站建设seo咨询服务价格
  • wordpress粒子北京公司要做seo
  • 电子商务网站建设的工具怎么引流到微信呢
  • 中国建行app官网下载安装北京seo排名技术
  • 网站页面小图标怎么做杭州产品推广服务公司
  • 开花店做网站链接买卖平台
  • 上海到北京飞机几个小时seo关键词优化培训班
  • 重庆做网站建设的公司哪家好谷歌搜索引擎下载安装
  • dw网站的滑屏怎么做电商培训机构哪家好
  • 商城网站 html模板1688精品货源网站入口
  • 网站美工培训上海网站排名优化怎么做
  • 怎么做购物网站的分类目录百度搜索关键词
  • 金融网站源码 aspseo的优点有哪些
  • 买服务器做网站主机引流推广广告怎么写
  • 深圳龙岗今日新闻头条上海专业seo排名优化
  • wap织梦手机网站小网站广告投放
  • php网站怎么建设优化公司组织架构
  • 做任务赚钱的网站代码广告软文代理平台
  • 实验楼编程网站杭州seo招聘
  • wordpress 首页 文章图片广州seo工程师
  • 网页设计师考证试题武汉seo人才
  • seo自带 网站建设如何写市场调研报告
  • app网站的电话是什么seo排名优化课程
  • ppt做的比较好的网站有哪些贵阳百度seo点击软件
  • 新手学做网站这本书济南网站优化
  • wordpress twenty fourteen主题做的演示网站百度账号安全中心官网
  • 网站建设定制网站建设公司哪家好搜索最多的关键词的排名
  • 百度一直不收录网站潍坊网站模板建站