随笔分类 -  c++

上一页 1 2 3 4 5 6 ··· 15 下一页
摘要:class A { int a; int b; int fun(){ return a; } }; class B : private A { public: void funB() { int num = fun();//private继承派生类函数 基类为private根本访问不了,能访问protected和public }... 阅读全文
posted @ 2017-04-02 19:31 zzyoucan 阅读(191) 评论(0) 推荐(0)
摘要:set ts=4 set expandtab set shiftwidth=4 set autoindent set smartindent 阅读全文
posted @ 2017-03-22 23:47 zzyoucan 阅读(214) 评论(0) 推荐(0)
摘要:class Rational { public: Rational(int numerator = 0, int denominator = 1); int numerator() const; int denominator() const; private: }; const Rational operator*(const Rational& lhs, ... 阅读全文
posted @ 2017-03-21 00:23 zzyoucan 阅读(143) 评论(0) 推荐(0)
摘要:template class SquareMatriBase{ protected: void invert(std::size_t matrixSize); }; template class SquareMatrix : private SquareMatriBase//private继承表示SquareMatrix由SquareMatriBase继承而来 { private: ... 阅读全文
posted @ 2017-03-19 17:22 zzyoucan 阅读(110) 评论(0) 推荐(0)
摘要:#include class CompanyA{ public: void sendCleartext(const std::string& msg){}; void sendEncrypted(const std::string& msg){}; }; class CompanyB{ void sendCleartext(const std::string& msg... 阅读全文
posted @ 2017-03-19 14:08 zzyoucan 阅读(172) 评论(0) 推荐(0)
摘要:#include template void f1(T(&ary)[bound]) { T x; for (int i = 0; i < bound; i++) { x = ary[i]; std::cout << x << std::endl; } } int main() { int a[] = { 1, 2, 3,... 阅读全文
posted @ 2017-03-05 13:29 zzyoucan 阅读(128) 评论(0) 推荐(0)
摘要:#include int main() { printf("this fake error is in %s on line %d\n", __FILE__, __LINE__); return 0; } 阅读全文
posted @ 2017-03-04 21:31 zzyoucan 阅读(180) 评论(0) 推荐(0)
摘要:内核时注意到有些函数会有添加__attribute__((unused)), 在gcc手册中找到了有关的解释: unused:This attribute, attached to a function, means that the function is meant to be possibly unused. GCC will not produce a warning f... 阅读全文
posted @ 2017-03-04 21:17 zzyoucan 阅读(1797) 评论(0) 推荐(0)
摘要:#include class String{ public: String(const String& str); String(const char* str); private: char* m_data; }; String::String(const String& str) { int len = strlen(str.m_data) + 1;//在... 阅读全文
posted @ 2017-02-28 18:27 zzyoucan 阅读(236) 评论(0) 推荐(0)
摘要:#include template class SquareMatrix{ public: void invert(); }; template void SquareMatrix::invert() { T num = n * 5; } int main() { SquareMatrix a; a.invert(); return 0; } 阅读全文
posted @ 2017-02-28 17:53 zzyoucan 阅读(150) 评论(0) 推荐(0)
摘要:转自http://www.linuxidc.com/Linux/2014-11/109545.htm 阅读全文
posted @ 2017-02-02 14:50 zzyoucan 阅读(5239) 评论(0) 推荐(0)
摘要:#include #include #include int main() { char* p = "123"; printf("%d\n", sizeof(p));//4 printf("%d\n", strlen(p));//3 std::cout << p + 1;//"23" return 0; } 阅读全文
posted @ 2017-01-04 22:32 zzyoucan 阅读(102) 评论(0) 推荐(0)
摘要:#include int main() { int a = 90; int*p = &a; printf("%p\n", p);//0138FE90 int* b = p + 1;//此处指针加1,移动4个字节,所以指针的值加4 printf("%p\n", b);//0138FE94 int c = b - p;//... 阅读全文
posted @ 2017-01-04 22:17 zzyoucan 阅读(136) 评论(0) 推荐(0)
摘要:#include #include struct cmp_str{ bool operator()(char const* a, char const* b){ return std::strcmp(a, b) v;//此时比较的是指针的值,今天差点这样用,如果这样需要自己写比较器 const char* a = "bello"; const cha... 阅读全文
posted @ 2016-12-05 23:58 zzyoucan 阅读(5799) 评论(0) 推荐(0)
摘要://类成员函数模板特化 #include class A{ public: template void Print(){ printf("A template\n"); } }; template void A::Print(){ printf("int\n"); } int main(){ A a; a.Print(); ... 阅读全文
posted @ 2016-12-03 21:19 zzyoucan 阅读(422) 评论(0) 推荐(0)
摘要:#include template T max(T x, T y) { return x > y ? x : y; } //函数模板特化 template const char* max(const char* x, const char* y){ return strcmp(x, y) > 0 ? x : y; } int main(){ std::cout ... 阅读全文
posted @ 2016-12-03 21:11 zzyoucan 阅读(1228) 评论(0) 推荐(0)
摘要:private成员,也被继承下来,只是不能访问 阅读全文
posted @ 2016-10-16 12:15 zzyoucan 阅读(116) 评论(0) 推荐(0)
摘要://每次写代码总是被迭代器的iter->和*iter弄晕,主要是被protobuf弄晕了 #include struct test{ test(){ memset(this, 0, sizeof(test)); } int a; int b; }; int main() { test a, b; a.a = a.b = 0;... 阅读全文
posted @ 2016-10-15 11:49 zzyoucan 阅读(467) 评论(0) 推荐(0)
摘要:class Rational{ public: const Rational operator*( const Rational& rhs); Rational(int num); private: int a; }; Rational::Rational(int num) :a(num) { } const Rational Rational::operator*(... 阅读全文
posted @ 2016-10-11 23:58 zzyoucan 阅读(167) 评论(0) 推荐(0)
摘要:以前对于指针直接比较总是不放心,包括std::find用法总感觉不放心,后面发现这种用法是可以的 阅读全文
posted @ 2016-10-07 21:47 zzyoucan 阅读(184) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 15 下一页