
C++
文章平均质量分 55
xin_y
这个作者很懒,什么都没留下…
展开
-
gdb调试或者打印地址时候为啥只有48位?
例如:0x7fffd2f48c10根本原因:当前的x86_64处理器硬件限制所致。因为目前面世的x86_64处理器的地址线只有48条,硬件要求传入的地址的48到63位必须与47位相同。因为这个相同的原因也就是说剩下的16位要那么是 0x0000 要么是0xffff 也就是说情况1(剩下的16位都是0):BIN二进制64位是 0000 0000 0000 0000 0000 0000 000...原创 2019-11-06 15:08:02 · 924 阅读 · 0 评论 -
字符串化操作符#得作用
#include <stdio.h>#define f(a, b) a##b#define g(a) #a#define h(a) g(a)int main(){ printf("%s\n", h(f(1,2))); printf("%s\n", g(f(1,2))); return 0;}//考察字符串化操作符#得作用得执行过...原创 2019-11-05 17:28:15 · 831 阅读 · 0 评论 -
用户态 内核态
原创 2017-12-18 17:37:30 · 216 阅读 · 0 评论 -
C++ 转换函数举例
#include<iostream>#include<vector>using namespace std;class A{ public: A(int a, int b) : a(a), b(b) {} inline int operator <<(int c) { return a + c;} inline oper...原创 2018-04-02 11:41:35 · 295 阅读 · 0 评论 -
C++ map 覆盖 前后插入比较 前数据被覆盖
#include<iostream>#include<map>#include <stdio.h>using namespace std;int main(){ std::map<int, int> a; std::map<int, int> b; a.insert(std::make_pair(1...原创 2018-12-20 11:43:14 · 2094 阅读 · 0 评论 -
函数指针的两个简单用法
/************************************************************************* > File Name: func.cpp > Author: yangjx > Mail: yangjx@126.com > Created Time: Sat 15 Dec 2018 12:28:19 PM C...原创 2018-12-15 13:17:50 · 184 阅读 · 0 评论 -
C 中 ptrdiff_t简单思考举例
#include<stdio.h>#include<stddef.h>struct stuff{ char name[16];};typedef struct stuff STF;STF array[] = { {"12"}, {"122"}, {"123"}, {"12s"}, {"12x"}, {"132翻译 2018-12-26 15:33:35 · 393 阅读 · 0 评论 -
extern "C" 与 __cplusplus 安全使用
无意中看源码看到的代码风格 如果已经宏定义 __cplusplus 则加入extern "C" 文件目录为/usr/include/event2/http_struct.h#ifndef _EVENT2_HTTP_STRUCT_H_#define _EVENT2_HTTP_STRUCT_H_/** @file event2/http_struct.h Data structure...原创 2018-12-25 20:20:45 · 183 阅读 · 0 评论 -
#if #if defined #if !defined #elif defined #else #elif !defined #ifndef #define
#if __WORDSIZE == 64typedef long int __quad_t;typedef unsigned long int __u_quad_t;#elif defined __GLIBC_HAVE_LONG_LONG__extension__ typedef long long int __quad_t;__extension__ typedef unsigned...原创 2019-01-02 14:18:45 · 6935 阅读 · 0 评论 -
C++ 实际项目中设置全局变量三种方法
#include<iostream>using namespace std;#include<stdlib.h>#include<stdio.h>/** method one *****/template<typename T>class Singleton{ public: static T& Instance(...原创 2019-01-11 18:21:22 · 6124 阅读 · 0 评论 -
C++ vector resize 后 之前保存数据是否清除(不清除)的测试用例
#include <iostream>using namespace std;#include<vector>#include<stdio.h>int main(){ std::vector<int> a; a.push_back(10); a.push_back(10); if(a.size() &l...原创 2019-01-07 17:55:30 · 6004 阅读 · 0 评论 -
C++ template模版长期举例总结
example_1#include<iostream>using namespace std;#include<stdio.h>template<typename T>class ID{ public: ID() : a(0) {} T getA() { return a;} void setA(T a_) { ...原创 2019-01-10 11:39:19 · 287 阅读 · 0 评论 -
c signal函数与system函数小应用
#include<sys/types.h>#include<iostream>#include<stdio.h>#include<stdlib.h>#include<errno.h>#include<unistd.h>#include<fcntl.h>#include<string.h原创 2019-01-22 14:40:33 · 483 阅读 · 1 评论 -
C++ new map erase delete 不delete时候重复使用问题 各种情况测试代码
#include <iostream>#include <map>using namespace std;#include <stdio.h>struct A{ int x; int y; A(int v1, int v2) : x(v1), y(v2) {}};class B{ public:/*...原创 2019-06-18 15:55:50 · 1340 阅读 · 0 评论 -
位操作实现m的n次方
#include <stdio.h>#include <stdlib.h>int pow(int m, int n){ int sum = 1; while(n != 0) { if(n&1 == 1) { sum *= m; } m *= m;...原创 2019-09-16 14:44:02 · 501 阅读 · 0 评论 -
C++ explicit关键字
首先, C++中的explicit关键字只能用于修饰只有一个参数的类构造函数, 它的作用是表明该构造函数是显示的, 而非隐式的, 跟它相对应的另一个关键字是implicit, 意思是隐藏的,类构造函数默认情况下即声明为implicit(隐式).#include #include #include using namespace std;class A{ publi翻译 2017-12-06 17:44:46 · 172 阅读 · 0 评论 -
C++中的mutable关键字
#include using namespace std;class A{ public: A() { count = 0; } ~A() {} void Out() const { std::cout << "ttttt" << std原创 2017-12-06 17:11:01 · 153 阅读 · 0 评论 -
C++运行时候库操作概述和整个程序运行流程
一、任何一个C/C++程序,它的背后都是一套庞大的代码来进行支撑,以使得该程序能够正常运行。这套代码至少包括入口函数、及其依赖的函数所构成的函数集合。当然,它还应该包括各种标准函数(如字符串,数学运算等)的实。一般的程序运行过程如下:1.操作系统创建进程后,把控制权交给程序的入口函数(gcc -e (_startEntryPoint)),这个函数往往是运行时库的某个入口函数,glibc的入口函转载 2017-01-16 11:58:37 · 998 阅读 · 0 评论 -
实例:linux下实现简单的socket 客户端 服务端
原理不再赘述文件构成:client.cppclient_socket.cppclient_socket.hMakefileserver.cppserver_socket.cppserver_socket.hsocket.cppsocket_exception.hsocket.h1.socket.h文件 主要实现基类#ifndef SOCKET_H#define转载 2017-01-19 00:06:34 · 575 阅读 · 0 评论 -
C++ 类复制
#includeusing namespace std;class A{ public: A(): a(0), b(0) {} A(int s, int ss): a(s), b(ss) {} int GetA() { return a;} A* clone() {原创 2017-02-10 18:00:44 · 928 阅读 · 0 评论 -
C++ shared_ptr 编译 error ‘shared_ptr’ was not declared in this scope修复
#include#include#include#includeusing namespace std;class Simple{ public: Simple(int p = 0) { number = p; std::cout << "Simple::" << number << st原创 2017-02-21 10:36:16 · 11390 阅读 · 0 评论 -
C++11 auto_ptr shared_ptr unique_ptr
转自: http://blog.youkuaiyun.com/xiejingfa/article/details/50750037 http://jingyan.baidu.com/article/9f7e7ec0b785ae6f281554f6.html http://blog.youkuaiyun.com/xiamentingtao/article/d翻译 2017-02-21 19:21:03 · 323 阅读 · 0 评论 -
C++ 基类 派生类 互相转换 调用关系
#includeusing namespace std;class A{ public: A(int a) : _a(a ) { std::cout << "this is A" << _a << std::endl; } void GetA() { std::cout << "get a" << std::endl; } public: int _a;原创 2017-03-04 01:04:49 · 471 阅读 · 0 评论 -
C++ 容器 new 删除问题
#include#includeusing namespace std;int main(){ std::vector a; int* b = new int(10); a.push_back(b); for(std::vector::iterator it = a.begin(); it != a.end();) { std::原创 2017-03-07 09:33:18 · 893 阅读 · 0 评论 -
C++ template简单应用
#includeusing namespace std;#includetemplateclass A{ private: T a;};templateclass A1 : public A{ private: V a1;};template, typename V = int>class B{ public原创 2017-03-09 14:45:54 · 356 阅读 · 0 评论 -
C++ 迭代器 it返回的内容以指针方式返回
#includeusing namespace std;#includeclass A{ public: int* GetA(int b) { for(std::vector::iterator it = _a.begin(); it != _a.end(); ++it) {原创 2017-03-13 11:21:39 · 5791 阅读 · 0 评论 -
C++ cant appear in a constant-expression bug修复
例:class KK{public: template void GetA() { A s; }};int main(){ int a = 14; KK s; s.GetA();}会报 a cant appear in a constant-expressio原创 2017-07-06 20:39:03 · 5623 阅读 · 0 评论 -
C++ 指针 new delete 赋值各种情况总结
#includeusing namespace std;int main(){ int* a = new int(100); std::cout << *a << " " << a << std::endl; //情况1 普通变量b /* * 结果 * 100 0x440f010 * 100 0x7fff6ff320d4原创 2017-08-02 11:16:36 · 2261 阅读 · 0 评论 -
模版 基类 父类 指针 正确保存数据
#include#include#includeusing namespace std;struct A{ int a; A():a(0) {} A(int ta) : a(ta) {}};struct AA:public A{ int aa; AA():A(), aa(0) {} AA(int ta, int taa): A(ta), aa(taa) {}};原创 2017-07-26 17:33:40 · 354 阅读 · 0 评论 -
析构函数声明为私有的作用
当我们规定类只能在堆上分配内存时,就可以将析构函数声明为私有的。class alloc{public: alloc():private: ~alloc();}; 如果在栈上分配空间,类在离开作用域时会调用析构函数释放空间,此时无法调用私有的析构函数。如果在堆上分配空间,只有在delete时才会调用析构函数。翻译 2017-11-28 18:59:43 · 1041 阅读 · 0 评论 -
函数指针的简单举例
#include using namespace std;void A(int a, int b){ std::cout << "AAA:" <<a << " " << b << std::endl;}void B(int a){ std::cout << "BBB:" <<a << std::endl;}typedef void (*FUNC_A)(int原创 2017-11-20 17:52:30 · 366 阅读 · 0 评论 -
main执行前后操作
之前操作:1.全局对象的构造函数2.标记__attribute__((constructor))属性的各个函数3.一些全局变量、对象和静态变量、对象的空间分配和赋初值之后操作:1.全局对象的析构函数2.atexit注册的函数3.标记__attribute__((destructor))属性的各个函数4.一些全局变量、对象和静态变量、对象释放空间、资源使用权等操作转载 2017-01-16 10:26:13 · 435 阅读 · 0 评论