
C++/C
juliosun
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
友元函数和友元类
友元函数和友元类 采用类的机制后实现了数据的隐藏与封装,类的数据成员一般定义为私有成员,成员函数一般定义为公有的,依此提供类与外界间的通信接口。但是,有时需要定义一些函数,这些函数不是类的一部分,但又需要频繁地访问类的数据成员,这时可以将这些函数定义为该函数的友元函数。除了友元函数外,还有友元类,两者统称为友元。友元的作用是提高了程序的运行效率(即减少了类型检查和安全性检查等都需转载 2013-04-08 18:03:50 · 526 阅读 · 0 评论 -
Essential C++ 学习笔记(六)
6.1 被参数化的型别 (Parameterized Types)在class template及其members的定义式中, 不需要以template parameter list进一步修饰class template. 除此之外,都需要以parameter list加以修饰.6.3 Template型别参数的处理在constructor定义式中,选择在member init原创 2013-05-01 15:40:05 · 640 阅读 · 0 评论 -
Essential C++ 学习笔记(七)
7 异常处理7.1 抛出异常 (Throwing an exception)抛出(throw)一个异常, 所谓异常(exceptions) 是某种对象.7.2 捕捉异常 (Catching an Exception)可以利用单一或连串的catch子句来捕捉(catch) 被抛出的异常对象.如果我们想要捕捉任何型别的异常, 可以用从catch-all的方式. catc原创 2013-05-04 16:20:01 · 594 阅读 · 0 评论 -
Forward Declaration of a Base Class 什么时候该用
You can not use forward declarations in any of those cases as the compiler needs to know the size of the class.You can only use forward declaration in a set of operations:declaring functions转载 2013-05-23 18:04:48 · 1748 阅读 · 0 评论 -
QvtkWidget 和 vtkImageViewer2 改变default mouse interactorStyle
重载的vtkInteractorStyleTrackballCamera 也可以是子类 vtkInteractorImage. 同时要注意qvtk 与vtkImageViewer的 RenderWindow与Interactor的共享, 多以qvtk为准. SetInteractor 一定要在 SetRenderWindow之前, 以避免error出现. "viewer.h"// Over原创 2013-05-23 17:56:21 · 4106 阅读 · 0 评论 -
QList 中的 append 和 push_back
void QList::pop_back ()This function is provided for STL compatibility. It is equivalent to removeLast(). The list must not be empty. If the list can be empty, call isEmpty() before calling this原创 2013-05-14 16:23:28 · 16242 阅读 · 2 评论 -
Static and dynamic libraries
A library is a package of code that is meant to be reused by many programs. Typically, a C++ library comes in two pieces:1) A header file that defines the functionality the library is exposing (of转载 2013-05-15 11:06:39 · 964 阅读 · 0 评论 -
可以将vector中的数据一次写入到二进制文件中吗
比如typdef struct index{ int offset; int lenght;}index;vector vec;vec.push_back();vec.push_back();........可以将保存在vector中的数据一次用fwrite写入到二进制文件中吗?还是要一个结构体一个结构体的写入呢?可以转载 2013-07-31 21:15:46 · 3942 阅读 · 2 评论 -
std::showpoint 显示小数点
std::showpointios_base& showpoint (ios_base& str);Show decimal pointSets the showpoint format flag for the str stream.When the showpoint format flag is set, the decimal point is always转载 2013-10-30 15:43:16 · 1221 阅读 · 0 评论 -
std::showpos 显示正号
std::showposios_base& showpos (ios_base& str);Show positive signsSets the showpos format flag for the str stream.When the showpos format flag is set, a plus sign (+) precedes every non转载 2013-10-30 15:43:57 · 3072 阅读 · 0 评论 -
How to fix the vtkCamera inverted y axis
Go back to the basics, it is actually quite simple. There is a right-handed coordinate system, the same in ITK and VTK. You must put your camera in a location in space, (defined in原创 2013-11-26 16:44:08 · 1297 阅读 · 0 评论 -
二叉树的遍历
树因为现实世界中存在这“树”这种结构——族谱、等级制度、目录分类等等,而为了研究这类问题,必须能够将树储存,而如何储存将取决于所需要的操作。这里有个问题,是否允许存在空树。有些书认为树都是非空的,因为树表示的是一种现实结构,而0不是自然数;我用过的教科书都是说可以有空树,当然是为了和二叉树统一。这个没有什么原则上的差别,反正就是一种习惯。二叉树二叉树可以说是人们假想的一转载 2013-05-01 15:22:20 · 582 阅读 · 0 评论 -
Essential C++ 学习笔记(五)
5.1 面向对象编程概念1. 面向对象风格的三个独特概念: 继承(inheritance), 多态(polymorphism), 动态绑定(Dynamic binding).2. 多态和动态绑定的特性, 只有在使用pointer或reference时才能发挥.5.2 面向对象编程思维1. 当程序定义出一个派生对象时, 基类和派生类的constructor都会被执行起来. 但原创 2013-04-29 15:29:08 · 654 阅读 · 0 评论 -
RTTI C++
Run-time type identificationRun-time type identification (RTTI) lets you find the exact type of an object when you have only a pointer or reference to the base type. This can be thought转载 2013-03-26 17:40:39 · 1867 阅读 · 0 评论 -
vector front back 与 begin end 的区别
std::vector::back" style="margin:0px; float:right; font-family:monospace; position:relative; top:-20px"> reference back();const_reference back() const;Access last elementReturns转载 2013-04-10 18:23:40 · 2511 阅读 · 0 评论 -
Essential C++ 学习笔记(四)
4. 基于对象的编程风格4.1 如何实现一个class1 前置声明使我们得以进行类指针(class pointer)的定义,或以此class作为数据类型.2 private members 只能在member function或是class friend内被取用.3 如果要在class 主体内定义, 这个member function会自动被视为inline函数.4.2原创 2013-04-22 16:29:20 · 819 阅读 · 0 评论 -
Maximum Munch Principle
Most STL users are already aware of the need to put an extra space when taking a template as a template argument to any class. For example when you want to make a vector of complex numbers, which is转载 2013-04-22 16:30:53 · 854 阅读 · 0 评论 -
insert adapters C++
Inserters (also called "insert iterators") are "iterator adaptors" that permit algorithms (the copy algorithm, for example) to operate in insert mode rather than overwrite mode, which is the default转载 2013-04-14 14:52:13 · 679 阅读 · 0 评论 -
Essential C++ 学习笔记(三)
Generic Programming3.1 指针的算术运算array 不会以传值方式复制, 但数组被传给函数,或是由函数中返回时,仅有第一个元素的地址会被传递.vectoe可以是空的,array则否.3.3 所有容器的共通操作end()返回一个iterator, 指向容器的最后一个元素的下一个位置.3.4 使用序列式容器1. vector以一块连续的内存存放元素. 对原创 2013-04-14 15:52:43 · 804 阅读 · 0 评论 -
linear search 和 binary search的区别
A linear search looks down a list, one item at a time, without jumping. In complexity terms this is an O(n)search - the time taken to search the list gets bigger at the same rate as the list does.转载 2013-04-15 12:32:05 · 4282 阅读 · 0 评论 -
C++ standard exceptions
Standard exceptionsThe C++ Standard library provides a base class specifically designed to declare objects to be thrown as exceptions. It is called exception and is defined in the header file und转载 2013-04-15 11:21:30 · 1194 阅读 · 0 评论 -
传值,传指针,传引用和传指针引用
无论你传值还是传指针,函数都会生成一个临时变量,但传引用时,不会生成临时变量,当你传值时,只可以引用值而不可以改变值,但传值引用时,可以改变值,当你传指针时,只可以改变指针所指的内容,不可以改变指针本身,但传指针引用时,即可以改变指针所指的内容,又可以改变指针本身,但传引用主要是它不生成临时变量,不进行返回值copy等,速度快。指向常量的指针:可以改变指针指原创 2013-04-24 12:25:37 · 869 阅读 · 0 评论 -
Google C++ Code Style
Header Files1. Define functions inline only when they are small, say, 10 lines or less2. When defining a function, parameter order is: inputs, then outputs3. Use standard order for reada转载 2013-04-24 20:01:01 · 1192 阅读 · 0 评论 -
vtkInteractor 几种模式
provide event-driven interface to the rendering window (defines trackball mode)vtkInteractorStyle is a base class implementing the majority of motion control routines and defines an event driven原创 2013-05-24 13:54:25 · 4392 阅读 · 0 评论 -
itk::ConfidenceConnectedImageFilter
templateclass itk::ConfidenceConnectedImageFilterSegment pixels with similar statistics using connectivity.This filter extracts a connected set of pixels whose pixel intensities are consiste转载 2013-12-03 14:53:18 · 1601 阅读 · 0 评论 -
vxl cannot build with share libs
I used CMake to create a MSVC project with BUILD_SHARED_LIBRARY=ON. But when I try to build, it gives message "cannot open vcl.lib". What's wrong?VXL does not support the CMake "Shared Library" feat转载 2013-12-30 16:05:59 · 749 阅读 · 0 评论 -
size_t 和 unsigned int, unsigned long
size_t是一些C/C++标准在stddef.h中定义的。这个类型足以用来表示对象的大小。size_t的真实类型与操作系统有关,在32位架构中被普遍定义为:typedef unsigned int size_t;而在64位架构中被定义为:typedef unsigned long size_t;size_t在32位架构上是4字节,在64位架构转载 2015-03-12 21:14:08 · 11377 阅读 · 1 评论 -
CMake get current directory
You can use the following:CMAKE_CURRENT_SOURCE_DIR: points to your current source directoryCMAKE_CURRENT_BINARY_DIR: points to the equivalent binary directory转载 2014-01-03 10:11:59 · 1248 阅读 · 0 评论 -
How to view include_directories in CMake
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)message("inc_dirs = ${inc_dirs}")转载 2014-03-06 01:12:41 · 768 阅读 · 0 评论 -
CMake 使用总结
CMake使用总结 前言 做第一个linux项目时,Makefile是一行行敲入的,第二个项目后,开始使用cmake。至于为何选择cmake,倒不是觉得它有什么好,仅仅是因为当时项目组中的一个linux前辈向我们推荐了这个。经过一番研究之后,并在项目中使用,现将使用经验总结一下,供大家参考。 入门篇 学习一项新知识的时候,最好是从sample开始转载 2012-09-18 20:36:07 · 1248 阅读 · 0 评论 -
Fast floor/ceiling functions C
IntroductionThose of you who are after sheer running speed already know how slow the standard floor/ceiling functions can be. Here are handy alternatives. Background The standard floor/ce转载 2015-10-19 23:46:56 · 535 阅读 · 0 评论 -
What does “warning: not all control paths return a value” mean? (C++)
Ifswitch case if cannot cover all cases, then the return value is undefined.Even though orientation is an enum with only two values (right now), it can still have a different value for any o转载 2015-10-28 00:28:47 · 975 阅读 · 0 评论 -
C++ 运算符优先级
The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending precedence.PrecedenceOperatorDescriptionAssociativity转载 2015-11-18 00:44:11 · 404 阅读 · 0 评论 -
vtk Camera
3.4 相机观众的眼睛就好比三维渲染场景中的相机,VTK则是用vtkCamera类来表示三维渲染场景中的相机。vtkCamera负责把三维场景投影到二维平面,如屏幕、图像等。图3.6为相机投影示意图。从图3.6可以看出与相机投影相关的因素主要有:l 相机位置:即相机所在的位置,用方法vtkCamera::SetPosition()设置。l 相机焦点:用方法vtk转载 2013-11-25 18:00:06 · 9983 阅读 · 4 评论 -
Fastest way to check if a file exist using standard C++
Well I threw together a test program that ran each of these methods 100,000 times, half on files that existed and half on files that didn't.#include #include #include inline bool exists_test0 (c转载 2016-08-17 20:35:13 · 615 阅读 · 0 评论 -
单精度与双精度浮点数
float是32位,double是64位float32位中,有1位符号位,8位指数位,23位尾数为double64位中,1位符号位,11位指数位,52位尾数位取值范围看指数部分float是有符号型,其中,8位指数位,2^8=(-128—127),因此实际的范围是-2^128—2^127,约为-3.4E38—3.4E38同理double范围约是-1.7E308—1.7E308,楼主可以自己按下计算器转载 2017-01-26 19:24:47 · 1879 阅读 · 0 评论 -
C++ 赋值运算符重载
Widget& operator=(const Widget& rhs) //返回类型是reference { //指向当前对象...原创 2015-03-10 18:54:56 · 1087 阅读 · 0 评论 -
Self-define float4 vector
The float4 structure encapsulates 4 float values and can be used to represent a 4-element vector or a row of a 4-column matrix:1234567891011转载 2015-03-06 00:02:09 · 1008 阅读 · 0 评论 -
安装AMD APP SDK 在 Intel 处理器上
想要安装opencl sdk 在机器上, 又没有显卡, 一个选择是用Intel自己的SDK. 但他有对SSE4.1的最低要求, 所以老的处理器不能用。 可以用AMD的sdk, 里面包含了opecl cpu runtime 和 opencl sample. 需要注意的是从AMD APP SDK 2.9 开始, cpu的runtime不再整合。 所以只能用之前的版本。安装2.8.1之后, 会有两个原创 2014-02-25 23:05:24 · 3100 阅读 · 0 评论 -
loop unrolling in C++
In the high-level view of a language, you're not going to see the optimization. The speed enhancement comes from what the compiler does with what you have.In the first case, it's something like:转载 2014-02-28 21:46:54 · 932 阅读 · 0 评论