SmartVessel

Foucs on C++

博客园 首页 新随笔 联系 订阅 管理

随笔分类 -  C and C++

1 2 下一页

摘要:1. 隐含的转化操作,例如把一个derived class指针转化为一个指向其public base type的指针sharp* ps = new circle();2. 经过virtual function机制3.经过dynamic_cast和typeid运算符circle *pc = dynamic_cast<circle*>(ps) 阅读全文
posted @ 2013-03-15 09:08 SmartVessel 阅读(498) 评论(0) 推荐(0) 编辑

摘要:constcv::Matinput=cv::imread("lena.jpg",0);//Loadasgrayscalecv::SiftFeatureDetectordetector;//cv::FastFeatureDetectordetector;std::vector<cv::KeyPoint>keypoints;detector.detect(input,keypoints);//Addresultstoimageandsave.cv::Matoutput;cv::drawKeypoints(input,keypoints,output);cv::imw 阅读全文
posted @ 2011-10-17 21:52 SmartVessel 阅读(578) 评论(0) 推荐(0) 编辑

摘要:1. 在头文件stdafx.h中增加一个自定义消息宏 #define WM_USER_THREADEND WM_USER + 1 2. 在于增加新消息的窗口或对话框类的头文件中增加一个回调函数声明,注意要声明为public afx_msg LRESULT OnUserThreadend(WPARAM wParam, LPARAM lParam); 3. 在窗口或对话框的cpp文件的BEGIN_MESSAGE_MAP,END_MESSAGE_MAP 中增加一行 ON_MESSAGE(WM_USER_THREADEND, OnUserThreadend) 4. 在窗口或对话框的cpp文件中增加回调 阅读全文
posted @ 2011-07-18 14:15 SmartVessel 阅读(19858) 评论(1) 推荐(0) 编辑

摘要:A simple (and perhaps overused) example of RAII is a File class. Without RAII, the code might look something like this: File file("/path/to/file");// Do stuff with filefile.close(); In other words, we must make sure that we close the file once we've finished with it. This has two drawb 阅读全文
posted @ 2011-07-11 16:10 SmartVessel 阅读(260) 评论(0) 推荐(0) 编辑

摘要:char *s = "xxxxx"; xxxx是存储在常量区的,这部分的内存是不能够写入的,实际上char *s为const char *即指针指向的内存的内容是常量型的不能够写。 char s[] = "xxxxx"; xxxxx数据存储在函数的栈中,是可以更改的。 阅读全文
posted @ 2011-06-29 10:49 SmartVessel 阅读(279) 评论(0) 推荐(0) 编辑

摘要:std::stringstr;chararray[]="HelloWorld";for(inti=0;array[i]!=0;i++)str+=array[i];//-----------------------------------std::stringstr;chararray[]="HelloWorld";str=array;Use of NULL is discouraged in C++ because it can be redefined to be anything one wants -- c++ standards do not d 阅读全文
posted @ 2011-05-12 09:39 SmartVessel 阅读(892) 评论(0) 推荐(0) 编辑

摘要:'static' can indeed be used in C++ to do what you want - to create a Static Member Function. The compiler message is actually telling you that the 'static' keyword is not valid on the definition of the method, it should only be used in the class definition. So the following compiles 阅读全文
posted @ 2011-05-05 15:12 SmartVessel 阅读(351) 评论(0) 推荐(0) 编辑

摘要:看了一个C源代码,这个C的lib广泛引用在包括firefox等很多地方看到如下的代码,百思不解staticintPTRCALLPREFIX(scanComment)(constENCODING*enc,constchar*ptr,constchar*end,constchar**nextTokPtr){if(ptr!=end){if(!CHAR_MATCHES(enc,ptr,ASCII_MINUS)){*nextTokPtr=ptr;returnXML_TOK_INVALID;}这函数定义,比较奇怪,突破我的知识范围了。我反复查了源代码,搞了一个多小时。所有的一切都是宏定义#ifndefP. 阅读全文
posted @ 2011-04-25 17:26 SmartVessel 阅读(268) 评论(0) 推荐(0) 编辑

摘要:intarrary[]={23,34,12,17,204,99,16};#defineTOTAL_ELEMENTS(sizeof(array))/sizeof(arrary[0])main(){intd=-1,x;if(d<=TOTAL_ELEMENTS-2){x=arrary[d+1]}}sizeof的返回类型是unsigned int。if语句中的,d由int类型被提升为unsigned int。结果-1变成正数255。if就不能被执行了。 总之,朝表示范围大的方向扩展:First, if either operand is long double, the other is con 阅读全文
posted @ 2011-04-24 21:14 SmartVessel 阅读(257) 评论(0) 推荐(0) 编辑

摘要:一篇很好的文章,介绍函数指针。http://www.cprogramming.com/tutorial/function-pointers.htmlA function pointer is a variable that stores the address of a function that can later be called through that function pointer. This is useful because functions encapsulate behavior. For instance, every time you need a particu. 阅读全文
posted @ 2011-04-22 10:26 SmartVessel 阅读(289) 评论(0) 推荐(0) 编辑

摘要:It's considered safer because a lot of people have "heard" that it's safer and then told others, who now have also "heard" that it's safer. Not a single person who understands references will tell you that they're any safer than pointers, they have the same flaws 阅读全文
posted @ 2011-04-18 11:41 SmartVessel 阅读(263) 评论(0) 推荐(0) 编辑

摘要:Summary from answers and links below: A pointer can be re-assigned any number of times while a reference can not be reassigned after initialization. A pointer can point to NULL while reference can never point to NULLYou can't take the address of a reference like you can with pointersThere's 阅读全文
posted @ 2011-04-18 09:54 SmartVessel 阅读(374) 评论(0) 推荐(0) 编辑

摘要:#include<iostream>#include<string>usingnamespacestd;voidmale(){cout<<"I'maman.\n";}voidfemale(){cout<<"I'mawoman.\n";}struct{(void)(*fn)();constchar*key;}function_lookup_table[]={{&male,"male"},{&female,"female"},{NULL,N 阅读全文
posted @ 2011-04-14 14:23 SmartVessel 阅读(206) 评论(0) 推荐(0) 编辑

摘要:糊涂了很久,看了别人的解释,似懂非懂的。今天终于看了stackoverflow里面的解释。自己写了点程序验证了下,终于明白了。局部变量:作用域在一个block里例如if(ture){inti=0;}i就是局部变量,作用域就在大括号里。再看function(){i=0;}局部变量实质在存放在函数的栈中,每一次invoke函数,都会产生变量i,多次调用i之间是不受影响的。#include<iostream>voidf();intmain(){f();f();return0;}voidf(){std::stringlocalA;localA+="ab";std::co 阅读全文
posted @ 2011-04-13 13:49 SmartVessel 阅读(315) 评论(0) 推荐(0) 编辑

摘要:A static global variable is local to the translation unit it is defined in. So, if you define static int a; in two different translation units, this will create two independent variables. If you define a non-static global variable int b; in two translation units, you will experience a linker error ( 阅读全文
posted @ 2011-04-13 11:09 SmartVessel 阅读(527) 评论(0) 推荐(0) 编辑

摘要:To simplify just a bit, there are basically three main storage areas you need to be concerned with: Global data -- a single static memory location outside the stack or heap. These are the variables declared not local to any function. (The distinction evident by the C/C++ "static" keyword i 阅读全文
posted @ 2011-04-13 10:26 SmartVessel 阅读(229) 评论(0) 推荐(0) 编辑

摘要:Take it with a grain of salt when you read it :) Well, the three things you refer to are automatic, static and dynamic storage duration, which has something to do with how long objects live and when they begin life. You use automatic storage duration for short lived and small data, that is needed on 阅读全文
posted @ 2011-04-13 10:19 SmartVessel 阅读(412) 评论(0) 推荐(0) 编辑

摘要:Summary of what static, heap, and stack memory are: A static variable is basically a global variable, even if you cannot access it globally. Usually there is an address for it that is in the executable itself. There is only one copy for the entire program. No matter how many times you go into a func 阅读全文
posted @ 2011-04-12 16:10 SmartVessel 阅读(428) 评论(0) 推荐(0) 编辑

摘要:一个路线图,如果做到就是神仙了 0.英语1.C++编程要向深入的地方推进2.网络编程3.多线程编程4.设计模式5.linux/unix6.数据库7.CRM架构(call center) 8.算法 阅读全文
posted @ 2010-01-08 16:50 SmartVessel 阅读(195) 评论(0) 推荐(0) 编辑

摘要:作者Blog:http://blog.csdn.net/SpitFire/ 在说内部连接与外部连接前,先说明一些概念。 1.声明 一个声明将一个名称引入一个作用域; 在c++中,在一个作用域中重复一个声明是合法的 以下都是声明: int foo(int,int); //函数前置声明 typedef int Int;//typedef 声明 class bar;//类前置声明 extern int ... 阅读全文
posted @ 2010-01-07 17:06 SmartVessel 阅读(378) 评论(0) 推荐(0) 编辑

1 2 下一页