![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
文章平均质量分 58
林海
学习中...
展开
-
c++中的虚函数和多态之间的关系
1.简介 虚函数是C++中用于实现多态(polymorphism)的机制。核心理念就是通过基类访问派生类定义的函数。假设我们有下面的类层次:class A{public: virtual void foo() { cout };c转载 2011-09-01 10:11:23 · 458 阅读 · 0 评论 -
c++初始化表
class A{ A(int x);//A的构造函数};class B{ B(int x, int y);//B的构造函数};B::B(int x, int y) :A(x) //在初始化表里调用A的构造函数转载 2011-08-26 13:23:39 · 372 阅读 · 0 评论 -
VC++ 如何隐藏使用STL而带来的大量警告
在你需要用到STL方面的头文件中加入#pragma warning(disable: 4786);当然,它只在当前源文件下有效,之后还有用到需要另外加注意:必须加在文件最开始原创 2011-09-28 16:14:47 · 408 阅读 · 0 评论 -
由rand7生成rand10以及随机数生成方法
舍去法一次rand7运算只能生成7个整数数,没有办法均匀的映射到10个整数上。但是运行两次rand7可以生成49个数字,如果这49个数字是均匀分布的,舍去多余的9个,剩下的40个正好可以映射到10个整数上。代码1int i;do{ i =转载 2011-10-12 11:08:22 · 687 阅读 · 0 评论 -
c++ 实现对文件的读取和查找(写暂时没写)
CPmap.h#pragma warning(disable: 4786) // vc中去除STL使用带来的警告#ifndef __CFGWRITER_H__ //防止重复调用头文件#define __CFGWRITER_H__#include "StdAfx.原创 2011-09-28 17:41:46 · 566 阅读 · 0 评论 -
专业术语记忆
CORBA--Common Object Request Broker Architecture 公用对象请求代理体系OO--object-oriented 面向对象OMG--Object Management Group 对象管理组REP--Request for原创 2011-09-21 10:52:27 · 385 阅读 · 0 评论 -
24点回溯法实现
// test11.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;原创 2011-10-12 14:40:21 · 1336 阅读 · 0 评论 -
24点游戏改进版---支持出题,解题运算
// test11.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"#include "string"#incl原创 2011-10-17 14:29:08 · 615 阅读 · 0 评论 -
linux多线程编程(实例)
是否熟悉POSIX多线程编程技术?如熟悉,编写程序完成如下功能:1)有一int型全局变量g_Flag初始值为0;2) 在主线称中起动线程1,打印“this is thread1”,并将g_Flag设置为13) 在主线称中启动线程2,打印“this is thread2”,并将g_Flag设置为24) 线程序1需要在线程2退出后才能退出5) 主线程在检测到g_转载 2011-10-31 17:49:03 · 755 阅读 · 0 评论 -
linux多线程编程(有关线程操作的函数)
#include int pthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*func) (void *), void *arg);int pthread_join (pthread_t tid, void ** status);pthread_t pthread_self (void);int pthr转载 2011-10-31 16:08:11 · 458 阅读 · 0 评论 -
linux 多线程1+2问题
设计如下功能:1、设置3个全局变量,初始值为0,分别用于加法的左右值和结果2、启动线程1,为g_left赋值为13、启动线程2,为g_right赋值为24、启动线程3,获取g_left+g_right的值5、线程3需要线程1和线程2执行完后执行代码:(linux下的多线程编程)#include "stdio.h"#include "stdlib.h"#inclu原创 2011-11-02 10:23:20 · 779 阅读 · 0 评论 -
linux sem信号量使用
Linux下关于信号量结构体表示为:sem_t 操作结构体的函数: 初始化函数: sem_init(sem_t * __sem,int __pshared,unsigned int __value); 触发信号量值:sem_post(sem_t * __sem); 等待信号量触发: 通常有:原创 2011-11-03 16:21:55 · 21167 阅读 · 2 评论 -
理解new和delete还有就是如何防止内存泄露
首先,new的话就是为对象在内存的堆中开辟一块内存空间比如说 int *p = new int(10);就是说从内存中分配一个足够大的内存来存放int变量。 delete p 释放内存关于内存泄露方面的问题1、 在使原创 2011-08-26 11:34:30 · 514 阅读 · 0 评论 -
引用和指针的区别个人理解
1、 指针被创建的时候,系统会为它分配一个计算机机长的内存空间,而引用创建时不分配内存空间,它只是一个别名2、 指针指向的是系统刚分配的内存空间,而引用则只是内存中已经存在的一块内存空间的别名3、 指针可以为空,而引用不行4、 指针的内存大小为一个计算机机长,原创 2011-08-26 11:06:46 · 245 阅读 · 0 评论 -
c++函数参数传递方式
1、非饮用传递 例子:int swap(int a,int b){int temp = b;b=a;a=temp;return a;}int num=swap(3,5);//num还是3,因为非饮用传递只改变了函数体内部的值,实参的值未原创 2011-09-01 11:07:44 · 281 阅读 · 0 评论 -
在类中定义常量的方法
问题:在类中建立一个int类型的数组方法一:(错误)class Test{ const int size = 100; int array[size];//……}; 错误原因:1:因为转载 2011-09-01 11:22:02 · 537 阅读 · 0 评论 -
c++中常函数的应用举例
#include using namespace std;class R{public:R(int r1, int r2) { R1=r1; R2=r2; }void print();void print() const;private:int原创 2011-09-02 14:24:21 · 534 阅读 · 0 评论 -
C++ 模板的概念
1. 模板的概念。我们已经学过重载(Overloading),对重载函数而言,C++的检查机制能通过函数参数的不同及所属类的不同。正确的调用重载函数。例如,为求两个数的最大值,我们定义MAX()函数需要对不同的数据类型分别定义不同重载(Overload)版本。//函数1.转载 2011-09-08 10:06:18 · 285 阅读 · 0 评论 -
关于vector的一段自用程序--初级
由于最近在看STL,关于string的操作,不例举了,今天把自学写的vector放上来,大家一起学习。#include "iostream"#include "vector"#include "string"#include "algorithm"usin原创 2011-09-09 13:44:20 · 369 阅读 · 0 评论 -
关于bitset 的一段代码--初级
#include#includeusing namespace std;int main(){//初始化16位bitvec1均为1bitset bitvec1(0xffff);cout//初始化32位bitvec2,1-16位为1,其它原创 2011-09-09 15:54:03 · 391 阅读 · 0 评论 -
关于list的一个例子
#include #include #include #include using namespace std; int main () {//assign() use the assign() fill the listint ary原创 2011-09-14 14:45:46 · 338 阅读 · 0 评论 -
编写一个pair存入一组string,int类型数据,并保持到vector中
例题:编写一个pair存入一组string,int类型数据,并保持到vector中#include#include#includeusing namespace std;int main(){ vector > ivec原创 2011-09-15 10:29:36 · 1046 阅读 · 0 评论 -
关于容器map的操作代码
#include#include#includeusing namespace std;int main(){typedef map M;M my_map;/*-----say how to insert value in the原创 2011-09-16 15:27:30 · 313 阅读 · 0 评论 -
STL中关于Set的部分功能实现
#include#include#includeusing namespace std;int main(){typedef set S;S my_set;/*----insert value in set----*/m原创 2011-09-16 16:40:54 · 328 阅读 · 0 评论 -
C++ 关于友元的一些程序
一、友元函数#includeusing namespace std;class Country;class Internet{public: Internet(char *name,char *address)原创 2011-09-15 17:26:37 · 109 阅读 · 0 评论 -
linux下的代码对比程序设计
操作系统为linux,可以移植到vc中,采用的是linux下的vim编辑器。vc下尝试也可以运行主要是考虑到在学习编程期间需要有很多的例子需要模仿网上或者书上的东西,然后,vim下没有提示功能,所以只能手动输入,这就有可能造成代码的输入错误,然后吧,就是悲剧,如果代码少的话还好,可以根据提示找错,顺便锻炼自己的纠错能力,但是错误满屏或者跟多就悲剧了吧,所以,就自己动手做了个文件对比程序。主要用原创 2011-11-07 16:20:10 · 742 阅读 · 0 评论