随笔分类 - c++
摘要:class A { int a; int b; int fun(){ return a; } }; class B : private A { public: void funB() { int num = fun();//private继承派生类函数 基类为private根本访问不了,能访问protected和public }...
阅读全文
摘要:set ts=4 set expandtab set shiftwidth=4 set autoindent set smartindent
阅读全文
摘要:class Rational { public: Rational(int numerator = 0, int denominator = 1); int numerator() const; int denominator() const; private: }; const Rational operator*(const Rational& lhs, ...
阅读全文
摘要:template class SquareMatriBase{ protected: void invert(std::size_t matrixSize); }; template class SquareMatrix : private SquareMatriBase//private继承表示SquareMatrix由SquareMatriBase继承而来 { private: ...
阅读全文
摘要:#include class CompanyA{ public: void sendCleartext(const std::string& msg){}; void sendEncrypted(const std::string& msg){}; }; class CompanyB{ void sendCleartext(const std::string& msg...
阅读全文
摘要:#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,...
阅读全文
摘要:#include int main() { printf("this fake error is in %s on line %d\n", __FILE__, __LINE__); return 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...
阅读全文
摘要:#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;//在...
阅读全文
摘要:#include template class SquareMatrix{ public: void invert(); }; template void SquareMatrix::invert() { T num = n * 5; } int main() { SquareMatrix a; a.invert(); return 0; }
阅读全文
摘要:转自http://www.linuxidc.com/Linux/2014-11/109545.htm
阅读全文
摘要:#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; }
阅读全文
摘要:#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;//...
阅读全文
摘要:#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...
阅读全文
摘要://类成员函数模板特化 #include class A{ public: template void Print(){ printf("A template\n"); } }; template void A::Print(){ printf("int\n"); } int main(){ A a; a.Print(); ...
阅读全文
摘要:#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 ...
阅读全文
摘要://每次写代码总是被迭代器的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;...
阅读全文
摘要: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*(...
阅读全文
摘要:以前对于指针直接比较总是不放心,包括std::find用法总感觉不放心,后面发现这种用法是可以的
阅读全文

浙公网安备 33010602011771号