![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
文章平均质量分 75
无_名_
将相本无神,男儿当自强。
展开
-
virtual析构函数的作用?
大家知道,析构函数是为了在对象不被使用之后释放它的资源,虚函数是为了实现多态。那么把析构函数声明为vitual有什么作用呢?请看下面的代码:1 #include 2 using namespace std;34 class Base5 {6 public:7 Base() {}转载 2013-05-27 21:13:34 · 615 阅读 · 0 评论 -
C++拷贝构造函数被调用的三种情况
C++拷贝构造函数被调用的三种情况一,当用类的一个对象去初始化该类的另一个对象时: int main(){ Point A(1,2); Point B(A); //用对象A初始化对象B,拷贝构造函数被调用 cout << B.GetX() << endl; return 0;}转载 2013-05-24 10:54:34 · 1719 阅读 · 0 评论 -
变量的生存期和可见性
在下面程序中体现了变量的生存期和可见性 #include using namespace std; int i = 1; //i为全局变量,具有静态生存期 int main() { static int a; //a为静态局部变量,具有全局寿命,局部可见 int b = -10;原创 2013-06-30 09:02:40 · 940 阅读 · 0 评论 -
C++语言异常处理
C++ 语言提供对处理异常情况的内部支持。try,throw,和catch语句就是C++语言中用于异常处理的机制。异常处理的语法throw 表达式try 复合语句catch(异常类型声明) 复合语句catch(异常类型声明) 复合语句 如果某段程序中发现了自己不能处理的异常,就可以使用throw表达式抛掷这个异常,原创 2013-06-29 16:20:05 · 728 阅读 · 0 评论 -
C++ STL
istream_iterator:输入迭代器。vector V;copy (istream_iterator(cin), istream_iterator(), back_inserter(V));ostream_iterator:输出迭代器。vector V;//…copy (V.begin(), V.end(), ostream_iterator(cout, "\n"));原创 2013-06-22 10:05:51 · 659 阅读 · 0 评论 -
函数模板与类模板
函数模板的定义形式:template 或类型名 函数名 (参数表){函数体的定义}#include using namespace std;template T abs (T x){ return x < 0? -x:x;}int main(){ int n = -5; double d = -5.5; cout << abs(n) << endl; co原创 2013-06-11 10:16:42 · 590 阅读 · 0 评论 -
C++字符串作函数参数/函数返回值
//C++字符串作函数参数#include using namespace std;void C (const char *str){ while(*str) { cout << *str ; str ++; } cout << endl;}int main(){ char mmm[15] = "mmmmmmm"; char *nnn = "nnnnnnn";原创 2013-06-02 20:12:11 · 7776 阅读 · 0 评论 -
C++继承
开始研究C++继承。先自己写一个试试……#include using namespace std;class J{public: void JJ() { cout << "88" << endl; }};class S : public J{public: void SS() { cout << "99" << endl; }};void main()原创 2013-06-08 13:50:32 · 846 阅读 · 0 评论 -
C++初始化列表
与其他函数不同,构造函数除了有名字,参数列表和函数体之外,还可以有初始化列表,初始化列表以冒号开头,后跟一系列以逗号分隔的初始化字段。class foo{ public: foo(string s, int i):name(s), id(i){} ; // 初始化列表 private: string name ;i原创 2014-01-05 18:36:11 · 1342 阅读 · 0 评论