ACM_C++系列
acceptedwwh
当代大学生,阳光开朗,乐于交往和求知!
展开
-
sort的用法
#include #include #include using namespace std;bool cmp(int i,int j){ return (i>j);}struct myclass { bool operator() (int i,int j){ return (i>j); }}myobject;int main () { in原创 2012-10-17 22:57:18 · 978 阅读 · 0 评论 -
C++虚基类(天大901)
#include using namespace std;class Base{ public: virtual Base* afn() { cout << "This is Base class.\n"; return this; }};class SubClass: public Base {p原创 2014-11-18 22:39:33 · 1190 阅读 · 0 评论 -
拷贝构造函数
#include using namespace std;class String {public: String(char *a) { str = new char[strlen(a)+1]; strcpy(str, a); } void print() { cout << str << endl; } ~String()原创 2014-11-18 23:06:26 · 665 阅读 · 0 评论 -
简单的构造与析构函数
#include using namespace std;class A {public: A(); A(int i, int j = 10); ~A(); void print();private: int a; int b;};A::A() { a = b = 0; cout << "A() called" << e原创 2014-11-18 22:56:33 · 761 阅读 · 0 评论 -
全局与静态的析构顺序
#include using namespace std;class Obj {private: int c;public: Obj(int cc):c(cc) { cout << "Obj::Obj()for" << c++ << endl; } ~Obj() { cout << "Obj::~Obj()for" << c原创 2014-11-22 22:32:37 · 716 阅读 · 0 评论 -
默认参数的构造函数与虚函数及常量初始化
#include using namespace std;class myclass { int a, b;public: myclass(int i = 0, int j = 0); void show();};myclass::myclass(int i, int j) { a = i; b = j; cout << "constru原创 2014-11-22 22:56:33 · 914 阅读 · 0 评论 -
不解的一段小程序
#include using namespace std;class x {public: int a, b, c; x() { a = b = c = 0; } x(int i) { a = i; b = c = 0; }};int x::*v[] = { &x::a, &x::b, &x::c}原创 2014-11-23 12:54:47 · 754 阅读 · 0 评论 -
纯虚函数
#includeusing namespace std;class A{public: virtual void print()=0;};class B:public A{ public: void print() { cout<<"This is B"<<endl; }};int main(){ B b;原创 2014-11-21 23:30:38 · 705 阅读 · 0 评论 -
关于全局全局静态局部局部静态的构造与析构顺序
#include #include using namespace std;class T{public: T(char *s) { strcpy(str, s); cout<<str<<"调用构造"<<endl; } ~T() { cout<<str<<"调用析构"<<endl; }private: char str[800];};T gob1("全局对原创 2014-11-22 23:25:40 · 849 阅读 · 0 评论 -
C++构造与析构函数
#include #include using namespace std;class A {public: A(){ a = 0; cout << "A's default constructor called.\n"; } A(int i) { a = i; cout << "A's constructor called.\n";原创 2014-11-29 23:10:43 · 830 阅读 · 0 评论 -
纯虚函数的入门程序
#include using namespace std;class original {public: original(int i = 0, int j = 0) { x0 = i; y0 = j; } virtual void set()=0; virtual void draw()=0;private: int原创 2014-12-05 23:18:55 · 740 阅读 · 0 评论 -
基类子类子对象的构造与析构顺序
#include using namespace std;class B1 {public: B1(int i) { b1 = i; cout << "constructor B1. " << i << endl; } ~B1() { cout << "destructor B1" << endl; }原创 2014-12-05 22:47:52 · 1969 阅读 · 0 评论 -
C++基础语法练习
#include #include using namespace std;class A{public: A(){ cout << "A's default constructor called" << endl; } A(int i) { a = i; cout << "A's constructor called" << endl;原创 2014-11-03 19:01:34 · 1546 阅读 · 0 评论 -
九度OJ1061成绩排序
九度OJ的一个网友遇到一个小问题,随便看了看找了出来,学ACM好多代码是C/C++混编的,其实对C++并不是很了解,有时间看看重载大于号的机制到底是怎么回事先学会怎么用。#include #include #include #include using namespace std;class StuInfo{ public: string strNam原创 2014-02-09 10:13:11 · 923 阅读 · 0 评论 -
sort(中间过程)
// sort algorithm example#include #include #include using namespace std;bool myfunction (int i,int j) { return (i<j); }struct myclass { bool operator() (int i,int j) { return (i<j);}} myobj翻译 2012-10-17 23:01:19 · 712 阅读 · 0 评论 -
堆排(库函数)
#include #include #include using namespace std;int main () { int a[] = {10,20,30,5,15}; vector v(a,a+5); vector::iterator it; make_heap (v.begin(),v.end()); cout << "initial max heap翻译 2012-10-17 23:12:56 · 895 阅读 · 0 评论 -
binary_search
// binary_search example#include #include #include using namespace std;bool myfunction (int i,int j){ return (i<j);}int main () { int myints[] = {1,2,3,4,5,4,3,2,1}; vector v(myints,翻译 2012-10-17 23:25:19 · 822 阅读 · 0 评论 -
class
#include #include using namespace std;class Rectangle { int width, height;public: Rectangle (int, int); int area (void) { return (width*height); }};Rectangle::Rectangle原创 2012-11-27 12:39:22 · 851 阅读 · 0 评论 -
栈的实现(C++)
#include #include using namespace std;template class set_stack { private: elemtype *elem; int top_p; int max_size; public: bool is_empty() const { return t原创 2012-11-30 22:07:52 · 814 阅读 · 0 评论 -
C++
#include using namespace std;class cat{ int age ; int weight ; public: void set(int x, int y); int f() ; cat(int age); ~cat();};cat::cat(int x){ ag原创 2012-11-30 22:12:04 · 670 阅读 · 0 评论 -
operator
#include using namespace std;class Display{ public: void operator() (std::string strin)const { std::cout << strin << std::endl; }};int main(){ Display f; f ("hello, w原创 2012-11-30 22:28:03 · 735 阅读 · 0 评论 -
隐藏基类的方法与调用
#include using namespace std;class mam{ public: void move() const {cout << "mammal move one step.\n"; } void move(int distance)const { cout << "mommal move";原创 2012-12-01 13:24:52 · 1300 阅读 · 0 评论 -
构造函数与析构函数(C++)
#include using namespace std;enum BREED{ black, red, white, blue};class mam{ public: mam(); ~mam(); int get_age()const { return age; } void set_age(int age1) {a原创 2012-12-01 13:26:12 · 877 阅读 · 1 评论 -
派生与私有保护
#include using namespace std;enum BREED{ black, red, white, blue};class mam{ public: mam(): age(4), weight(5){}; ~mam(){} int get_age()const { return age; } voi原创 2012-12-01 13:29:02 · 940 阅读 · 0 评论 -
C++中的pair
#include #include #include #include #include #include using namespace std;void test1() { std::pair foo (10,'a'); std::pair bar (90,'z'); swap (foo,bar); std::cout << "foo contains翻译 2013-04-21 22:51:53 · 1448 阅读 · 0 评论 -
多重继承中派生类的构造函数
#include using namespace std;/********************在多重继承中,派生类的构造函数与单继承下派生类构造函数相似,它必须负责该派生类所有基类构造函数以及对象成员(如果有的话)构造函数的调用。同时,派生类的参数必须包含完成所有基类、对象成员以及派生类中新增数据成员初始化所需的参数。派生类构造函数执行顺序如下: (1)所有基类的构造函数,多原创 2014-12-14 22:37:38 · 5193 阅读 · 0 评论