
C/C++
yongye_
贵有恒,何必三更眠五更起;最无益,只怕一日曝十日寒。
展开
-
C++ nullptr与auto
1 nullptr and std::nullptr_t C++11提供了nullptr用来取代0或者NULL。在C++11之前,使用NULL为空指针赋初值,但NULL其实就是0,这时会把NULL当成0来用。如下代码#include <iostream>using namespace std;void f(void*) { cout << "void*" <...原创 2019-12-06 10:53:58 · 319 阅读 · 0 评论 -
C++常量成员函数、参数传递
1 常量成员函数(const member functions)class Complex {public: Complex(double r = 0, double i = 0) :re(r), im(i) {} Complex(double r) :re(r), im(0) {} Complex& operator += (const Complex&); d...原创 2019-11-29 12:46:08 · 1136 阅读 · 0 评论 -
C++ 构造函数
1 类的声明 有些函数直接在类内定义,另一些在类外定义。class Complex {public: Complex(double r = 0, double i = 0) :re(r), im(i) {} Complex& operator += (const Complex&); double real() const { return re; } double...原创 2019-11-27 22:28:06 · 204 阅读 · 0 评论 -
C++中class的分类
对于C++中的类而言,最经典的一种分类方法是根据类中数据成员的是否带指针来区分。可分为两种:一种是类中数据成员不带指针,另一种是带着指针的。 如下所示:不带指针class Complex {private: double re, im;};带指针,一个指针在32位平台上占用4字节,64位上占用8个字节class String {private: char* m_d...原创 2019-11-27 14:54:57 · 927 阅读 · 0 评论 -
C 位运算符与
位运算符作用于位,并逐位执行操作。#include <stdio.h>int main(){ int a = 0 & 0; int b = 1 & 0; int c = 0 & 1; int d = 1 & 1; printf("a = %d\n", a); printf("b = %d\n", b); printf("c = ...原创 2019-04-15 17:19:45 · 291 阅读 · 0 评论