
C++
人气小哥
少种的少收,多种的多收,这话是真的.----<圣经>哥林多后书9:6
展开
-
【转】 C/C++位域(Bit-fields)之我见
前言很早想说说这个问题了,经常也会有很多公司拿位域出来考人,呵呵要真的想弄清楚还要一点点的分析。这里先看看网宿的一道笔试题目,这道题目我之前是复制网上的,结果不对,修改了一下,可以正确运行了,谢谢(imafish_i )提醒://假设硬件平台是intel x86(little endian) typedef unsigned int uint32_t; void inet转载 2009-05-16 15:04:00 · 881 阅读 · 0 评论 -
lua中导出C++类中的弱表
weak table是什么意思,建议不要看中文翻译的,我以前看了半天还是没懂啥子意思.lua 手册原文是这样解释的:A weak table is a table whose elements are weak references. A weak reference is ignored by the garbage collector. In other words, if t转载 2014-04-21 17:42:27 · 363 阅读 · 0 评论 -
VS2010中的C++0x特性 以后有时间在看
#include #include #include using namespace std;//自动类型 + 匿名函数void Case1(){ vector v; for (int i = 0; i < 10; ++i) { v.push_back(i); } auto fun = [](int n) -> void { cout << n << " "; };转载 2014-04-09 14:23:46 · 314 阅读 · 0 评论 -
在Lua中调用C++函数
#include extern "C"{#include "lua.h"#include "lualib.h"#include "lauxlib.h"}#pragma comment(lib,"E:\\luaSRC\\lua5.1\\lib\\static\\lua5.1.lib")/* avg.lua文件内容avg, sum = average(10, 20, 30,原创 2014-04-10 10:45:43 · 259 阅读 · 0 评论 -
好久没有写操作符重载了 自己重新写了个 温习了一下细节 温习友元 this const 引用
#include using namespace std;class Point{public:Point(int _x, int _y) : x(_x), y(_y){}void setPoint(int _x,int _y){x = _x;y = _y;}void print(){cout"}fri原创 2014-05-19 14:30:44 · 457 阅读 · 0 评论 -
记住常量指针 和指针常量的区别
int a = 5;int b = 19;int c = 27;int d = 44;//const int* p1 = &a;//int const* p3 = &c;//p1 = &d;//p3 = &d;//*p1 = d;//*p3 = d;int* const p2 = &b;*p2 = d;p2 = &d;原创 2014-04-28 19:01:10 · 314 阅读 · 0 评论 -
C++11 lambda表达式 实际上是lua的闭包方式
// lambda.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "iostream"using namespace std;#include #include #include #include int _tmain(int argc, _TCHAR* argv[]){ //范例1 auto func = []()原创 2016-07-15 20:04:13 · 1425 阅读 · 0 评论 -
基类指针创建子类对象 构造顺序 面试必考
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "iostream"using namespace std;class A{public: A() { cout << 1 << ends; func1(); } ~A() { cout << 2 << en原创 2016-07-07 19:29:46 · 553 阅读 · 0 评论 -
关于异或的用法1交换整数(注意陷阱)2求整数序列中差的一个值
#include "stdafx.h"#include "iostream"using namespace std;//****************************************//异或交换整数 陷阱 不能传同一个值去交换/*void exchange(int &a, int &b){ //没有判断是否相等 BUG函数 a ^= b; b ^= a;原创 2016-08-04 15:04:55 · 399 阅读 · 0 评论 -
位移遍历输出整数2进制
void Binarycout(int n){ for (int i = 31; i >= 0; i--) { cout>i)& 1); } cout<<endl;}原创 2016-08-04 15:28:19 · 619 阅读 · 0 评论 -
lua作为配置文件被C++读取
/*lua作为配置文件被C++读取配置需包含文件..\devenv\include\lua5E:\game\devenv\include需将lua5d.dll拷贝到exe目录*/extern "C"{#include "lua.h"#include "lualib.h"#include "lauxlib.h"}#include #include #include原创 2014-04-08 11:19:33 · 408 阅读 · 0 评论 -
lua 与的C api交互操作
extern "C"{#include "lua.h"#include "lualib.h"#include "lauxlib.h"}#include #include #include using namespace std;static void stackDump (lua_State *L) //输出所有lua栈内函数{ int i; int top = l原创 2014-04-04 17:54:19 · 300 阅读 · 0 评论 -
【转】C++ sizeof 使用规则及陷阱分析
因为我转的也是别人转过的东西,别人没有写原帖地址,那么我也不写了。算了 还是写个吧,别人也转得挺幸苦:http://blog.youkuaiyun.com/li002qwe/archive/2009/05/14/4187049.aspx 1、什么是sizeof 首先看一下sizeof在msdn上的定义: The sizeof keyword gives the amount of转载 2009-05-15 11:48:00 · 369 阅读 · 0 评论 -
C++ 位域之我见
今天之前没有接触过位域这个概念,这个概念也很少有书提及。深入研究之后终于明白了。。。先以下面的例子进行剖析:我的理解是 位域是为了节省更多的空间。但是过多的节省空间,缺并未做存储界限检查,可能会导致 存储数据丢失的现象。首先我们来分析为什么是16。这是大家都知道的位的概念8bit(位)=1Byte(字节) 1024Byte(字节)=1KB 1024KB原创 2009-05-16 01:35:00 · 1988 阅读 · 1 评论 -
位域具体存放数值测试,终极版
#include #include using namespace std;void main(){ struct test { unsigned int a:16;//在这里测试就可以发现其规律,有无unsigned、a:1 a:2 a:4 a:8 a:16 a:32 以及用char的各值来试验就可发现位域的规律 我就不多说了 }; test t1; t原创 2009-05-16 16:12:00 · 337 阅读 · 0 评论 -
ASCII码10换行 和 13回车
ASCII码10 和 1310是换行键,13是回车键。我个人认为这两个概念是从打字机沿用过来的。换行只是表示宽度已经到达显示的终点了,需要换一行显示,接下来还是上文的延续。回车则表示一个段落已经结束,需要开启新的段落。比如在Windows里,记事本有个自动换行的功能,起始就是在需要换行的地方添加了换行符。(没有验证)还比如,在QQ或其他即时通讯软件里,总是存在回车或是Ctr转载 2014-03-14 14:03:42 · 4449 阅读 · 0 评论 -
使用位操作,减少除法和取模的运算。
实现高效的C语言编写的第三招--使用位操作,减少除法和取模的运算。在计算机程序中,数据的位是可以操作的最小数据单位,理论上可以用“位运算”来完成所有的运算和操作。一般的位操作是用来控制硬件的,或者做数据变换使用,但是,灵活的位操作可以有效地提高程序运行的效率。举例台如下:方法Gint I,J;I=257/8;J=456%32;方法Hint转载 2014-03-18 09:48:49 · 1748 阅读 · 0 评论 -
c++按位操作符
c++按位操作符顾名思义,按位运算符允许按照位来操作整型变量。可以把按位运算符应用于任意signed和unsigned整型,包括char类型。但是,它们通常应用于不带符号的整型。这些运算符的一个常见应用是在整型变量中使用单个的位存储信息。例如标记,它用于描述二进制状态指示符。可以使用一个位来描述有两个状态的值:开或关、男或女,真或假。也可以使用按位运算符处理存储在一个变转载 2014-03-19 11:33:17 · 517 阅读 · 0 评论 -
C++友元类详解
#include #include class Point { public: Point(double xx, double yy) { x=xx; y=yy; } void Getxy(); friend double Distance(Point &a, Point &b); private: double x, y; };转载 2014-05-04 13:58:09 · 321 阅读 · 0 评论 -
explicit 关键字声明 不能隐式调用构造函数
class Test1{public: Test1(int n) { num = n; } //普通构造函数private: int num;};class Test2{public: explicit Test2(int n) { num = n; } //explicit(显式)构造函数private: int num;};int main(){ Test1 t转载 2014-05-04 15:50:20 · 366 阅读 · 0 评论 -
学习使用stringstream stream;
再进行多次转换的时候,必须调用stringstream的成员函数clear().#include #include int main(){std::stringstream stream;int first, second;stream<< "456"; //插入字符串stream >> first; //转换成intstd::cout << first << std:转载 2016-09-17 14:12:33 · 448 阅读 · 0 评论