随笔分类 - C/C++
关于C/C++的东西
摘要:编译环境vc 9#ifndef SCANALLFILES_H#define SCANALLFILES_H#include "boost/filesystem/operations.hpp"#include "boost/filesystem/path.hpp"#include <iostream>using namespace std;class ScanAllFiles{public: static const vector<string>& scanFiles(const string&,vector<s
阅读全文
摘要:Student& st = CollegeStudent("eatman",22);其中CollegeStudent是Student的子类g++编译报错:main.cc: In function ‘int main()’:main.cc:8: error: invalid initialization of non-const reference of type ‘Student&’ from a temporary of type ‘CollegeStudent’临时对象是const的。所以const Student& st = CollegeSt
阅读全文
摘要:C++泛型模板类使用小结:泛型类可以让源代码“实现”文件cc 和 头文件分离,书写规则只要遵循如下所示:文件一:Test.h的泛型模版类的头文件#include <iostream>#ifndef TEST_H#define TEST_Htemplate <typename T>class Test{ private: T t; public: void echo(void); //这个方法就一个功能,把私有的T类型成员变量打印出来 Test(T);};#include "Test.cc" //注意这里,引入了他的"实现文件",代
阅读全文
摘要:转载自:http://www.ibm.com/developerworks/aix/library/au-unix-eclipse/index.htmlBuild UNIX software with EclipseBringing legacy code into a modern IDEChris Herborth (chrish@pobox.com), Freelance, Freelance WriterSummary: Become more productive with your own code and others by utilizing Eclipse's syn
阅读全文
摘要:类似java或python的string的replace方法?string replace( pos ,len , new_str ); C++的string的replace的原始定义的第一个参数起始替换下标,第二个参数是从起始替换下标开始替换的len个字符,第三个参数是new_str.与python的字符串替换略有不同,现在比如我要把str = "Hello world mac"中的mac替换成jobs1. 替换第一次出现的字符串mac(只替换第一次出现的字符串,不是replaceAll):string old_word= "mac";string h
阅读全文
摘要:续上一篇《C++模板类(泛型类)学习总结》(网址:http://www.cnblogs.com/sharpstill/archive/2012/01/27/2330059.html),现在问题来了,我建立了一个MotherStudent<Student*>* mother_std 的指针,我想要析构这个MotherStudent里的children(vector<T>,该T是一个Student*指针),我如何析构一个装满指针的容器?贴出上次修改过的博文里的代码如下:(注意红笔)int _tmain(int argc, _TCHAR* argv[]){ // Mother
阅读全文
摘要:调试了一下午,发现用C++写模板方法真是有不少值得注意的地方,不是一般的麻烦,没点经验总结真是不行的。首先,写模板类(template class),这个在java叫作泛型类,需要注意几点,在写泛型类时.h头文件和实现(.cpp)不能分离,也就是说,关于泛型类/模板类的所有逻辑都 要写在一个文件中,我的做法是将类的函数体和函数原型都写入头文件,而省去.cpp的implement的文件。头文件如下:#ifndef MOTHER_STUDENT_H#define MOTHER_STUDENT_H#include "Student.h"#include <vector>
阅读全文
浙公网安备 33010602011771号