
C++语言理解
tong_xin2010
这个作者很懒,什么都没留下…
展开
-
C++ primer 5th edition:7.1.2节(关于this指针;关于const member functions)
一:关于this有一个类Sales_data,有一个这个类的object:Sales_data total;当我们使用这个object中的一个member函数时,例如(total.isbn()),compiler会implicitly传给isbn函数total这个object的地址,用于初始化isbn函数中隐藏的this这个parameter。compiler的这个操作造成的效原创 2014-02-22 15:52:55 · 645 阅读 · 0 评论 -
C++:编写自己的函数时要keep in mind
2014.2函数的返回类型可以是reference to an object,例如:// return a reference to the shorter of two strings(C++ primer 5th edition)const string &shorterString( const string &s1, const string &s2){ return原创 2014-02-19 15:33:43 · 517 阅读 · 0 评论 -
C++:关于OOP的key ideas之一的data abstraction
2014.4.13参考材料:C++ Primer 5th edition (Chap 7, Chap 15)1. Data abstraction是一项programming/design technique。通过separation of interface and implementation得以实现data abstraction.(附加我的理解:要区分开C++中class和da原创 2014-04-13 22:06:16 · 1071 阅读 · 0 评论 -
C++ primer 5th :第15章面向对象程序设计
15.2.31:关于原创 2014-06-03 11:14:07 · 655 阅读 · 0 评论 -
C++:关于class member声明为static的情况
2014.5.27reference: C++ primer 5th, $7.6:Static Class MembersTOPIC 1:一个类中的member(data member和function member)可以声明为static,需要申明为static的情况有一下原因:1:使用的客观需要:需要某个member是associated with the class,not wi原创 2014-05-27 15:52:56 · 1581 阅读 · 0 评论 -
【转】虚函数和纯虚函数的区别
首先:强调一个概念定义一个函数为虚函数,不代表函数为不被实现的函数。定义他为虚函数是为了允许用基类的指针来调用子类的这个函数。定义一个函数为纯虚函数,才代表函数没有被实现。定义纯虚函数是为了实现一个接口,起到一个规范的作用,规范继承这个类的程序员必须实现这个函数。1、简介假设我们有下面的类层次:[cpp] view plaincopy转载 2014-06-03 15:02:21 · 430 阅读 · 0 评论 -
C++: Type Conversion (数字,指针,其他type)
参考材料:C++ primer 5th, 4.11起因是UNIX中一些函数返回void *指针,使用之前要转换成char *指针使用,不清楚会出现什么现象,所以找到type conversion来看*************************************************************************************第一部分是i原创 2014-07-10 11:02:29 · 867 阅读 · 0 评论 -
C++:为什么inline函数的定义要放在头文件里 + inline和宏定义的区别(暂未体会到)
1 ——》为什么inline函数的定义要放在头文件里(注意使用qian)转载 2014-08-27 20:50:48 · 1407 阅读 · 0 评论 -
C++:copy initialization & direct initialization
参考材料:C++ primer 5th edition &13.1.1原创 2014-08-12 20:50:18 · 803 阅读 · 0 评论 -
C++:【转】3种继承关系和3中访问权限
对基类进行继承时,三种继承方式下,基类的三种访问权限在子类中会有如何的变化这个问题,本科时上C++这门课的时候曾仔细的分析并弄得挺清楚,后来时间久了、用的也不多,慢慢的又变得心里不太有谱了。这次接着准备面试的契机,又重新仔细分析了一番,留个案底,以免再犯糊涂。三种访问权限 public:可以被任意实体访问 protected:只允许子类及本类的成员函数访问转载 2014-08-27 22:27:21 · 674 阅读 · 0 评论 -
C++:pass by reference的时候真正传递的是什么?
如果窥视c++编译器的底层,你会发现,references往往以指针实现出来,因此pass-by-reference通常意味着这真正传递的是指针。转载 2014-08-27 22:02:53 · 1386 阅读 · 0 评论 -
【转】VS2010 设置main函数输入参数
http://blog.youkuaiyun.com/yihaizhiyan/article/details/37659645 点击打开链接转载 2014-11-11 11:20:55 · 2007 阅读 · 0 评论 -
【程序问题】函数计算值正确,但是返回值赋给另一个变量却变成另一个值
出现问题程序如下:#include "LZAP.h"#include "string.h"int main(){ int i; double a; for(i = 1;i <62; ++i) { FILE* record; char datafile[20]; sprintf(datafile, "out-2048-LZAP-%d.txt",i);原创 2015-01-16 21:06:24 · 1236 阅读 · 0 评论 -
自动化读入批量数据,进行实验
int main(){ int i; double a; for(i = 1;i <62; ++i) { char inputname[10]; char outputname[20]; double a = 0; FILE* record; char datafile[20]; sprintf(inputname,"%d.txt",i); sprin原创 2015-01-16 21:16:56 · 516 阅读 · 0 评论 -
C++:与字符串常量有关的几个重要概念string literal, string, C-style charater string
参考资料:C++ primer 5th edition(1) 3.5.4 "C-Style Character Strings"(2) 3.5.1 "Character Arrays Are Special"(3) 3.2.1 "Defining and Initializing 'string's "(4) 2.1.3 "Character and Character Strin原创 2014-04-02 16:07:54 · 2502 阅读 · 0 评论 -
C++:对于class来说,什么函数可以在class里面定义,什么函数最好在class外面定义(我的理解)
2014.4.15今天在看Data Structus原创 2014-04-15 16:55:59 · 2279 阅读 · 0 评论 -
C++: 为什么我们一般都要将函数的声明和定义分开?(separate the declaration of function from its definition)
2014.4.14参考材料:C++ Primer原创 2014-04-14 14:49:22 · 2124 阅读 · 0 评论 -
C++:一个函数是member function还是只是part of the interface
根据C++primer 5th的7.1节和7.2.1的第一段,我的理解是一个函数的声明,如果是在包含一个类的定义的头文件里(可能在class定义里面的public中,也可能在class的定义外面),则这个函数就是这个类的interface的一部分。而一个函数,只要是在一个类的定义中间出现,不管它是在类的public部分还是private部分,它都是这个类的member functi原创 2014-02-23 10:56:32 · 607 阅读 · 0 评论 -
C++:关于什么对象要放到class的public范围中,什么对象放到class的private范围中
参考材料:C++ primer 5th edition 7.2节:BENEFITS OF ENCAPSULATION我的理解是:public和private的区分的同义词是“权限的区分”,而做这种区分的目的是encapsulation(封装)。那么,什么样的什么对象要放到class的public范围中,什么对象放到class的private范围中呢?根据参考材料,我的理解就原创 2014-02-23 17:22:12 · 1873 阅读 · 0 评论 -
C++:name lookup的规则(我的理解,未确定正确性)
参考材料:C++ primer 5th edition 7.4.1节首先,明确name lookup是个什么工作。name lookup, "the process of findging which declarations match the use of a name"。这个工作是compiler做的事情然后,我暂时对compiler做name lookup原创 2014-02-24 09:29:09 · 990 阅读 · 0 评论 -
C++中scope和lifetime的理解
(说明:这是看完C++ primer(第五版)P204的理解)关于scope和lifetime这两个概念,有以下几个需keep in mind:1.“In C++,names have scope, andobjects have lifetimes.”这两个概念讲的是不同东西的特点“The scope of name is the part of the progra原创 2014-02-18 17:05:47 · 3145 阅读 · 0 评论 -
C++:在函数parameter passed by reference时,如果可能,尽量使其是reference to const
TOPIC:在函数parameter passed by reference时,如果在使用这个函数过程中,你无需改变参数的值,那么应该(一定)使其具有形式func_type function(const para_type &)2014.2:C++ primer 5th edition 6.2.3节也就是说,在函数不需要改变参数的值时,不应该只把paramater的类型定为plain re原创 2014-02-18 21:42:14 · 1763 阅读 · 0 评论 -
C++:关于函数调用时的argument passing是by reference还是by value
2014.2根据C++ primer 5th edition 6.2节,有个关键理解:When the argument value is "passed by value", the argument value is "copied", the parameter and argument are "independent";when argument is "passed原创 2014-02-18 21:10:19 · 1638 阅读 · 0 评论 -
C++:关于const类型
在看“Data Structures,Algorithms,and applications in C++”时,一个类中写了如下几个函数,让我如此混乱:bool IsEmpty() const {return length;}LinearList& Insert(int k, const T& x);void Output(ostream& out)const;让我思考不清的问题是原创 2014-03-02 20:13:02 · 925 阅读 · 1 评论 -
C++:关于type alias
type alias常用在:当声明一个复杂的类型时,用type alias是很常用的routine如何使用type alias:C++ primer 5th edition 2.5.1节原创 2014-02-19 15:53:23 · 679 阅读 · 0 评论 -
C++:在C++中什么时候需要加上std::
那是命名空间,你所用到的很多函数或者类都是被放到命名空间里面的,命名空间是防止名字重复而使用的,比如STL有个类叫string,而你也设计一个类叫string,那么编译器编译的时候就搞不清楚到底是那个string,所以用一个命名空间就比较方便了。具体是这么回事的,比如有两个班级,A班和B班,两个班各有一个叫张三的人,而两个班的同学相互之间都是非常熟悉的。那么他们聊天的时候说张三,那其他人肯定会问,转载 2014-02-19 15:45:52 · 9414 阅读 · 6 评论 -
关于argument和parameter的分别
以下面这段话作为理解的根据(The type of a parameter determines the interaction between the parameter & its argument. If the parameter is a reference, then the parameter is bound to its argument. Otherwise, the argu原创 2014-02-18 21:03:31 · 634 阅读 · 0 评论 -
C++: 关于function的declaration与definition的关系(函数声明和定义的关系)(并附一篇转载文章)
以下材料都来源于C++ primer 5th edition1(Chap 6):重要概念(有时问题想不明白可以带着这个概念再去思考)A function is a block of code with a name.//We execute the code by calling the function.2(2.2.2:Variable Declarations and原创 2014-03-10 16:45:12 · 2659 阅读 · 0 评论 -
C++:关于template与friend联合出现的问题
1(C++ primer 5th edition 7.2.1: Declarations for Friends)A friend declaraton only specifies access. It is not a general declaration of the function.//If we want users of the class to be able to ca原创 2014-03-10 15:33:31 · 1103 阅读 · 0 评论 -
C++:Initialization, assignment & copying有什么不同
。原创 2014-04-13 20:37:33 · 769 阅读 · 0 评论 -
C++:VS遇见的错误(持续)
1:有的时候报错:missing a ";" 很有可能需要( )或者[ ],但你却给出了{ }2:error 2143: missing ')' 写成了while (auto it = S.begin(); it !=S.end(); ++i )应是:for (auto it = S.begin(); it !=S.end(); ++i )3:er原创 2014-03-04 22:07:10 · 711 阅读 · 0 评论