c++基础
freedom311
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 191 阅读 · 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 · 814 阅读 · 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 · 245 阅读 · 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 · 204 阅读 · 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 · 590 阅读 · 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 · 489 阅读 · 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 · 259 阅读 · 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 · 271 阅读 · 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 · 635 阅读 · 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 · 615 阅读 · 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 · 440 阅读 · 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 · 303 阅读 · 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 · 377 阅读 · 0 评论 -
C++ 类的静态成员详细讲解
一、静态成员函数中不能调用非静态成员。 二、非静态成员函数中可以调用静态成员。因为静态成员属于类本身,在类的对象产生之前就已经存在了,所以在非静态成员函数中是可以调用静态成员的。 三、静态成员变量使用前必须先初始化,否则会在linker时出错。转载 2017-10-23 14:31:33 · 207 阅读 · 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 · 268 阅读 · 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 · 258 阅读 · 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 · 359 阅读 · 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 · 383 阅读 · 0 评论 -
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 · 233 阅读 · 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 · 2931 阅读 · 1 评论 -
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 · 509 阅读 · 0 评论 -
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 · 381 阅读 · 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 · 212 阅读 · 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 · 226 阅读 · 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 · 220 阅读 · 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 · 228 阅读 · 0 评论 -
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 · 211 阅读 · 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 · 329 阅读 · 2 评论 -
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 · 169 阅读 · 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 · 179 阅读 · 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 · 174 阅读 · 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 · 201 阅读 · 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 · 221 阅读 · 0 评论 -
c++基础(4)
#include <iostream> using namespace std;int main() { /* code */ int n = 10; mylable: cout << n << ", "; n--; if (n >0) { goto mylable; } cout << "lift off! \n";翻译 2017-09-29 16:16:28 · 152 阅读 · 0 评论 -
C++基础(12)
#include <iostream> using namespace std;void increment_all (int *start, int *stop) { int *current = start; while (current != stop) { ++(*current); ++current; } } void print_翻译 2017-09-30 15:19:09 · 230 阅读 · 0 评论 -
c++基础(13)
#include <iostream> using namespace std;void increase (void *data, int psize) { if (psize == sizeof(char)) { char * ch; ch = (char *)data; ++(*ch); } else if (psize == sizeof(int))翻译 2017-09-30 15:40:54 · 236 阅读 · 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 · 237 阅读 · 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 · 245 阅读 · 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 · 355 阅读 · 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 · 262 阅读 · 0 评论
分享