
c/c++
HLongSh
这个作者很懒,什么都没留下…
展开
-
java与c++运算符优先级
int x = 1; int y = 1; int sum = x + y + (--y * 2);求上面代码sum的值c++的自增自减运算符优先级最高所以是x(1)+y(0)+(0*2);java并不是这样的,自增自减运算符跟+号是平级的,所以从左到右,因为是表达式相加,所以从左到右是x(1)+y(1)+(0*2);...原创 2018-03-16 05:24:38 · 242 阅读 · 0 评论 -
友元函数&虚函数
被友元的虚函数,是可以被继承的三个类Myclass,Myclass2,son,Myclass对Myclass2的set函数友元,son继承Myclass2,如果son不重写set函数,而是直接继承Myclass2的set,是可以操作Myclass私有属性的。#include <iostream>using namespace std;class MyClass;class My...原创 2018-03-21 09:34:50 · 3690 阅读 · 0 评论 -
c++类成员的函数指针
#include<iostream>#include<string>using namespace std;class MyClass{public: int a = 55; static void go(){ cout << "2" << endl; } void pr(){ cout << a <..原创 2018-03-26 00:15:25 · 151 阅读 · 0 评论 -
c++tuple模版元编程分析
c++的tuple可以装载任何的类型,用法示例:std::tuple<int, char> a(10, 'x'); std::cout << " " << std::get<0>(a); std::cout << " " << std::get<1>(b); 先上一原创 2018-04-01 14:33:53 · 331 阅读 · 0 评论 -
c++私有继承无法直接进行转换
c++私有继承无法直接进行转换,但是可以在子类内部提供一个函数进行转换#include <stdio.h>#include <iostream>#include <tuple>class fu{public: int a = 100;};class zi:private fu{public: int a = 99; fu convert...原创 2018-04-01 17:38:39 · 632 阅读 · 0 评论 -
boost:bind解析
mybind.h实现:#ifndef BOOST_BIND_BIND_HPP_INCLUDED__Mybind#define BOOST_BIND_BIND_HPP_INCLUDED__Mybind#include <iostream>using namespace std;namespace boost { //占位符对象 template<int I> ...原创 2018-04-14 23:01:06 · 287 阅读 · 0 评论 -
极简的std::function
#include <iostream>using namespace std;template<class F>class Myfun{};template<class R,class F>class Myfun<R(F)>{public: Myfun(R(*f)(F)){ this->_fun = f; } ...原创 2018-04-15 10:04:52 · 118 阅读 · 0 评论 -
c++仿函数
#include <iostream> using namespace std;class MyClass{public: void operator ()(int a){ cout << a<<endl; }private:};template<class T>void run(T t){ t(100);...原创 2018-04-04 04:23:17 · 393 阅读 · 0 评论 -
单调栈&单调队列入门
单调队列比较难理解代码,所以自己加了点注释#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;struct node{ int x, y;}v[101]; //x表示值,y表示位置 可以理解为下标int a[...转载 2018-04-06 07:14:09 · 313 阅读 · 0 评论 -
c++跟java后置自增运算符的不同
int a = 10; cout << (a++) + (++a+a ) << endl;//输出33int a = 10; System.out.println((a++) + (++a+a));//输出34java会在下一个运算的时候就把a++的值加上,而c++会在整个表达式结束后进行自增。并没有谁对谁错,只是编译器实现上的不同而已。...原创 2018-04-13 22:16:27 · 253 阅读 · 0 评论 -
bind1st实现
#include <algorithm>#include <iostream>using namespace std;template<typename _Arg1, typename _Arg2, typename _Result>struct binary_function2 { typedef _Arg1 first_argument_type...原创 2018-04-14 07:06:38 · 310 阅读 · 0 评论 -
weak_ptr简单实现
#include <iostream>class Counter{public: Counter() :s(0), w(0){}; int s; int w;};template<class T> class WeakPtr;//为了用weak_ptr的lock(),来生成share_ptr用,需要拷贝构造用template<class T>...原创 2018-04-24 23:11:41 · 2983 阅读 · 0 评论 -
qt使用boost
打开cmd,进入boost库所在的目录 找到build.bat,然后执行以下命令编译b2和bjambuild mingw1我的build.bat在F:\boost_1_56_0\tools\build\src\engine 编译完之后在当前目录会生成一个bin.ntx86的目录,进入后有b2.exe和bjam.exe可执行文件,将这两个文件拷贝到boost源代码的根目录下执行安装bjam --to...原创 2018-05-10 23:37:22 · 587 阅读 · 0 评论 -
内存分配步骤
原创 2018-03-25 08:41:06 · 554 阅读 · 0 评论 -
恶心的函数指针
(┬_┬)我是一个函数我叫Register,我的参数是一个函数指针他长这样(int(*)(const char *, const char *)),我的返回值类型是一个函数指针,他长这样(int(*)(const char *, const char *))下面就是我#include<iostream>int fun(const char *, const char *){ re...原创 2018-03-20 19:04:34 · 260 阅读 · 0 评论 -
类模板当作一个类模板的模板参数
#include<iostream>#include<string>using namespace std;//类模板当作一个类的参数//设计STL时候用到//面试,类模板当作参数class MyClass{public:private:};template<class T>class MyClass2{public: T...原创 2018-03-24 09:25:08 · 2149 阅读 · 0 评论 -
关于一道cout题目
最终输出什么?#include<iostream>#include<stdlib.h>int main(){ int a = 1; std::cout << (a++) << (a++) <<(a++) ; system("pause"); return 0;}一开始是认为输出123,运行后发现输出321搜了...原创 2018-03-11 05:29:25 · 177 阅读 · 0 评论 -
对于C/C++,java的volatile关键字的个人理解
C/C++中的volatile是禁止编译器对变量的操作进行优化,每次读取需要从内存读取,不允许从cpu缓存或者寄存器中取值。参考文章:http://blog.youkuaiyun.com/qq_29350001/article/details/54024070java中volatile有主要2个功能第一个,禁止重排序,在变量前与变量后的语句即使重排序也不会交换到变量的前面或者后面。int a=1;//可能与b...原创 2018-03-17 15:11:26 · 874 阅读 · 0 评论 -
指针相减运算
#include int main () { int a=10; int *p=&a; int *pp=p+5; printf("%d",pp-p); //同类型指针相减 (pp-p)/sizeof(int) 如果类型不同无法做运算 return 0;}原创 2018-02-25 01:26:59 · 507 阅读 · 0 评论 -
二维数组与指针
c无法直接返回一个数组 char str[5][10] = { "calc", "notepad", "tasklist", "pause", "mspaint" }; printf("%p,%p,%p", str, &str, *str); //指针地址的一样,但是类型不一样 //str代表行地址,&str代表整个数组的地址,*str就是第一个字符的原创 2018-02-25 01:04:27 · 159 阅读 · 0 评论 -
c++函数包装器
类似于jdk的动态代理一样,其实只是一个函数接受一个函数指针调用一下...#include<iostream>#include<functional>using namespace std;template<typename T, typename F>T run(int a,T v, F f)//代理类{ std::cout << "执...原创 2018-03-12 07:29:32 · 508 阅读 · 0 评论 -
c++重载箭头运算符
一句话:对箭头的返回值做->操作,如果返回值重载了->则调用重载的。 a)如果返回的是一个指针将调用内置的箭头运算符。执行相当于(*(p.operator->()).mem;的操作。 b)如果返回是一个重载了箭头运算符的对象,则继续对该对象调用其重载了的箭头运算符,直到返回的是一个指针,将对该指针调用a)的操作。操作相当于(*(p.operator->()....原创 2018-03-18 04:52:31 · 382 阅读 · 0 评论 -
纯C语言简单模拟C++的虚函数表
原文:http://blog.youkuaiyun.com/smstong/article/details/50669732多态,面向接口编程等设计方法并没有绑定到任何特定的语言上,使用纯C也可以实现简单的多态概念。下面给出一个非常简单粗糙的例子,只为说明概念。父类Animal定义 文件:animal.h#ifndef ANIMAL_H#define ANIMAL_H/* 方法表, 类似于C++的虚函...转载 2018-03-19 06:36:04 · 991 阅读 · 1 评论 -
c++ref()函数
使用std::ref可以在模板传参的时候传入引用,否则无法传递#includetemplatevoid com(T arg){ std::cout <<"com ="<< &arg << "\n"; arg++;}void main(){ int count = 10; int & rcount = count; com(count); std::cout <<原创 2018-03-13 07:41:11 · 9011 阅读 · 0 评论 -
虚函数原理
看了一下虚函数,原理不难理解,反倒最后的二维数组看不懂了,回顾一下二维数组的遍历概念二维数组:二维数组的第一个[]等于每一个指向一维数组地址的指针(行指针),第二个[]等于指向数据的指针。二维数组遍历方式:void func3(int (* p)[3], int row, int col){ for(int i=0; i<row; ++i){ for(int ...转载 2018-03-19 14:06:08 · 237 阅读 · 0 评论 -
c++可变参数完美转发
c++语法真的怪异看线程源码的时候看到一段template<class _Fn, class... _Args> explicit thread(_Fn&& _Fx, _Args&&... _Ax) { // construct with _Fx(_Ax...) _Launch(&_Thr, _STD bind(_Deca...原创 2018-03-13 20:58:56 · 3366 阅读 · 2 评论 -
typename的历史及用法
typename有2个用法1标明其后的模板参数是类型参数2模板中标明“内嵌依赖类型名”主要作用就是消除歧义下面这个会产生歧义,加了typename编译器就会认为是个内嵌依赖类型。从而不会出现template <class T>void foo() { T::iterator * iter; //不写typename 有可能解析为T类的静态变量iterator 假如iterat...转载 2018-03-13 22:55:15 · 244 阅读 · 0 评论 -
友元与模板类
友元成员函数模板:#include <iostream>using namespace std;template<class T> class A; //当用到友元成员函数时,需注意友元声明与友元定义之间的互相依赖。这是类A的声明template<class T>class B{public: void set_show(int x, A...转载 2018-03-24 09:28:28 · 428 阅读 · 0 评论