![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++基础
freedom311
这个作者很懒,什么都没留下…
展开
-
c++中implicit members
#include <iostream>#include <string>using namespace std;class Rectangle { int width, height;public: Rectangle (int x, int y) : width(x), height(y) {} Rectangle () = default; Rectangl翻译 2017-11-03 15:56:40 · 300 阅读 · 0 评论 -
c++虚拟成员函数
// virtual members#include <iostream>using namespace std;class Polygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; } virtual int翻译 2017-11-07 16:37:56 · 514 阅读 · 0 评论 -
C++中基类指针
// pointers to base class#include <iostream>using namespace std;class Polygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; }};class R翻译 2017-11-07 16:19:12 · 513 阅读 · 0 评论 -
c++中多重继承
// multiple inheritance#include <iostream>using namespace std;class Polygon { protected: int width, height; public: Polygon (int a, int b) : width(a), height(b) {}};class Output { publ翻译 2017-11-07 14:15:16 · 196 阅读 · 0 评论 -
c++类之间的继承
#include <iostream>using namespace std;class Polygon {protected: int width, height;public: void set_values (int a, int b) { width = a; height = b; }};class Rectangle : p翻译 2017-11-07 13:17:40 · 176 阅读 · 0 评论 -
c++中friend class
// friend class#include <iostream>using namespace std;class Square;class Rectangle { int width, height; public: int area () {return (width * height);} void convert (Square a);};c翻译 2017-11-07 09:16:37 · 392 阅读 · 0 评论 -
c++中friend function
#include <iostream>using namespace std;class Rectangle { int width, height;public: Rectangle () {} Rectangle (int x, int y) : width (x), height (y) {} int area () {return width * hei翻译 2017-11-07 09:12:58 · 476 阅读 · 0 评论 -
c++重载运算符
#include <iostream>using namespace std;class CVector {public: int x, y; CVector () {}; CVector (int a, int b) : x(a), y(b) {} CVector operator + (const CVector&);};CVector CVector::o翻译 2017-10-20 17:07:44 · 140 阅读 · 0 评论 -
c++类指针
#include <iostream>using namespace std;class Rectangle { int width, height;public: Rectangle (int x, int y) : width(x), height(y) {} int area (void) {return width * height;}};int main(i翻译 2017-10-20 14:16:46 · 171 阅读 · 0 评论 -
c++中抽象基类
#include <iostream>using namespace std;class Polygon { protected: int width, height; public: Polygon (int a, int b) : width(a), height(b) {} virtual int area (void) =0; void printa翻译 2017-11-07 16:46:19 · 314 阅读 · 0 评论 -
c++重载操作符续
#include <iostream>using namespace std;class CVector {public: int x, y; CVector () {} CVector (int a, int b) : x(a), y(b) {}};CVector operator+ (const CVector & lhs, const CVector & rhs翻译 2017-10-23 10:35:12 · 117 阅读 · 0 评论 -
c++中this关键字
#include <iostream>using namespace std;class Dummy {public: bool isitme (Dummy& param) ;};bool Dummy::isitme (Dummy& param) { if (¶m == this) { return true; } else {翻译 2017-10-23 13:20:22 · 242 阅读 · 0 评论 -
c++中move constructor and assignment
#include <iostream>#include <string>using namespace std;class Example6 { string* ptr;public: Example6 (const string& str) : ptr(new string(str)) {} ~Example6 () {delete ptr;} //move翻译 2017-11-03 15:38:48 · 397 阅读 · 0 评论 -
C++中copy constructor
#include <iostream>#include <string>using namespace std;class Example5 { string* ptr; public: Example5 (const string& str) : ptr(new string(str)) {} ~Example5 () {delete ptr;} // co翻译 2017-11-03 15:22:30 · 2743 阅读 · 1 评论 -
c++析构函数
#include <iostream>#include <string>using namespace std;class Example4 { string* ptr;public: Example4 () : ptr (new string) {} Example4 (const string& str) : ptr (new string (str)) {}翻译 2017-11-03 11:31:45 · 155 阅读 · 0 评论 -
C++默认构造器
#include <iostream>#include <string>using namespace std;class Example3 { string data;public: Example3 (const string& str) : data(str) {} Example3 () {} const string& content () const翻译 2017-11-03 11:05:10 · 291 阅读 · 0 评论 -
c++模板特化
// template specialization#include <iostream>using namespace std;// class template:template <class T>class mycontainer { T element; public: mycontainer (T arg) {element=arg;} T increa翻译 2017-10-24 16:49:59 · 246 阅读 · 0 评论 -
c++类模板
#include <iostream>using namespace std;template <class T>class mypair { T a, b; public: mypair (T first, T second) {a=first; b=second;} T getmax ();};template <class T>T mypair<翻译 2017-10-24 16:26:58 · 181 阅读 · 0 评论 -
c++常量成员函数
#include <iostream>using namespace std;class MyClass { int x; public: MyClass (int val) : x (val) {} const int& get () const {return x;} };void print (const MyClass& ar翻译 2017-10-24 11:46:31 · 180 阅读 · 0 评论 -
C++ 类的静态成员详细讲解
一、静态成员函数中不能调用非静态成员。 二、非静态成员函数中可以调用静态成员。因为静态成员属于类本身,在类的对象产生之前就已经存在了,所以在非静态成员函数中是可以调用静态成员的。 三、静态成员变量使用前必须先初始化,否则会在linker时出错。转载 2017-10-23 14:31:33 · 131 阅读 · 0 评论 -
c++构造器中成员函数初始化
#include <iostream>using namespace std;class Circle { double radius;public: Circle (double r) : radius (r) {} double area () {return radius*radius*3.1415926;}};class Cylinder { Circl翻译 2017-10-20 13:59:26 · 708 阅读 · 0 评论 -
c++统一初始化
#include <iostream>using namespace std;class Circle { double radius; public: Circle (double r) {radius = r;} double circum () {return 2*radius*3.1415926;}};int main(int argc, char co翻译 2017-10-20 13:31:18 · 198 阅读 · 0 评论 -
c++默认构造函数
#include <iostream>using namespace std;class Rectangle { int width, height; public: Rectangle (); Rectangle (int,int); int area (void) {return (width*height);}};Rectangle::Rectangle翻译 2017-10-20 13:15:10 · 227 阅读 · 0 评论 -
c++基础(8)
#include <iostream>using namespace std;int addition(int a, int b) { int r; r = a + b; return r;}int main(){ int z; z = addition(2, 3); cout<<"the result is:\n"<<z<<endl;翻译 2017-09-29 16:30:17 · 119 阅读 · 0 评论 -
c++基础(7)
#include <iostream>using namespace std;int main(){ int x; cout << "enter a number:\n"; cin >> x; switch (x) { case 1: case 2: case 3: cout << "x i翻译 2017-09-29 16:28:48 · 117 阅读 · 0 评论 -
c++基础(6)
#include <iostream>using namespace std;int main(){ for (int i = 10; i > 0; --i) { if (i == 5) { continue; } cout << i << ", "; } cout << "li翻译 2017-09-29 16:27:33 · 105 阅读 · 0 评论 -
C++基础(5)
#include <iostream>using namespace std;int main(){ for (int n = 10; n> 0; n--) { cout << n << ", "; if (n == 3) { cout << "countdown aborted!"<< "111111111111翻译 2017-09-29 16:25:47 · 209 阅读 · 2 评论 -
c++基础(3)
#include <iostream>#include <string>#include <sstream>using namespace std;int main(){ string mystr; float price = 0; int quantity = 0; cout << "Enter price: "; getline (cin,mystr翻译 2017-09-29 16:15:04 · 145 阅读 · 0 评论 -
c++基础(2)
#include <iostream>#include <string>using namespace std;int main(){ string mystr; cout << "What's your name? "; getline(cin, mystr); cout << "Hello " << mystr << ".\n"; cout << "What is yo翻译 2017-09-29 16:13:14 · 159 阅读 · 0 评论 -
C++基础(1)
#include <iostream>using namespace std;# define PI 3.1415926#define NEWLINE '\n'int main(){ /* code */ double r = 5.0; double circle; int foo = 0; auto bar = 8; decltype(fo翻译 2017-09-29 16:01:45 · 154 阅读 · 0 评论 -
C++基础
#include<iostream>using namespace std;int main(){ int a = 5; int b(2); int c{1}; a = a + b; int result = a - c; cout << "result is:\n" << result<<endl; return 0;}翻译 2017-09-29 15:59:16 · 130 阅读 · 0 评论 -
c++基础(9)
#include <iostream>using namespace std;void printmessage() { // printf("%s\n", "hello,world!"); cout << "I'm a function!";}int main(int argc, char const *argv[]){ printmessage(); re翻译 2017-09-29 16:31:18 · 143 阅读 · 0 评论 -
c++基础(10)
#include <iostream>using namespace std;void duplicate(int &a, int &b, int &c) { a*=2; b*=2; c*=2;}int main(){ int x=1, y=2, z=3; duplicate(x,y,z); cout << "x=" << x << ", y="翻译 2017-09-30 11:07:11 · 119 阅读 · 0 评论 -
C++基础(11)
#include <iostream>using namespace std;int main(int argc, char const *argv[]){ int numbers[5]; int * p; p = numbers; *p = 10; p++; *p = 20; p = &numbers[2]; *p = 30; p = num翻译 2017-09-30 13:09:21 · 137 阅读 · 0 评论 -
c++基础(19)
#include <iostream>using namespace std;class Rectangle { int width, height; public: Rectangle (int,int); int area () {return (width*height);}};Rectangle::Rectangle (int a, int b) { wi翻译 2017-10-20 11:42:23 · 196 阅读 · 0 评论 -
c++基础(18)
#include <iostream>using namespace std;class Rectangle { int width, height;public: void set_values (int, int); int area () {return width*height;}};void Rectangle::set_values (int x, in翻译 2017-10-20 11:19:28 · 115 阅读 · 0 评论 -
c++基础(17)
#include <iostream>#include <string>#include <sstream>using namespace std;struct movies_t { string title; int year;};int main(int argc, char const *argv[]){ string mystr; movies_t翻译 2017-10-19 17:13:05 · 177 阅读 · 0 评论 -
C++基础(16)
#include <iostream>#include <string>#include <sstream>using namespace std;struct movies_t{ string title; int year; } mine, yours;void printmovie (movies_t movie) ;int main(int argc, char翻译 2017-10-19 16:49:44 · 176 阅读 · 0 评论 -
C++基础(15)
#include <iostream>#include <new>using namespace std;int main(int argc, char const *argv[]){ int i, n; int *p; cout << "How many numbers would you like to type? "; cin>>i; p = n翻译 2017-10-19 15:42:34 · 181 阅读 · 0 评论 -
c++基础(14)
#include <iostream>using namespace std;int addition (int a, int b){ return (a+b); }int subtraction (int a, int b){ return (a-b); }int operation (int x, int y, int (*functocall)(int,int)){ int g;翻译 2017-09-30 16:19:03 · 167 阅读 · 0 评论