《C++primer》第四版 15.3.1节提到基类到派生类转换(无论ref/poniter or not)的可行性,有些拗口,根据英文版翻译,得到以下几个要点:1.如果是public继承,则用户代码和后代类都可以使用派生类到基类的转换。2.如果类是使用private或protected继承派生的,...
分类:
其他好文 时间:
2015-11-15 17:47:38
阅读次数:
181
1、问题的引入
1).观察以下第一块代码:
#include
using namespace std;
class Screen{
public:
void test(){
dummy_fcn( );
}
void dummy_fcn( ){
}
};
此代码编译无错误。。。。。。。。。。。...
分类:
编程语言 时间:
2015-06-11 21:18:22
阅读次数:
163
总结一下C++中string的操作,来自〈C++ Primer〉第四版。1. string对象的定义和初始化:12345678910111213string s1; //空串string s2(s1); //将s2初始化为s1的一个副本string s3("value...
分类:
编程语言 时间:
2015-05-22 16:47:05
阅读次数:
171
习题9.26:假设有如下ia的定义,将ia复制到一个vector容器和一个list容器中。使用单个迭代器参数版本的erase函数将list容器的奇数值 元素删除掉,然后将vector容器中的偶数值删除掉。代码:#include #include #include #include using...
分类:
编程语言 时间:
2015-05-10 20:09:53
阅读次数:
140
#include
#include
#include
using namespace std;
int main()
{
vector spvec;
string str;
while(cin>>str)
{
string *sp = new string;
*sp = str;
spvec.push_bac...
分类:
编程语言 时间:
2015-05-07 22:14:45
阅读次数:
168
#include
#include
int main()
{
std::vector ivec;
int temp;
while(std::cin>>temp)
ivec.push_back(temp);
int *cp =new int[ivec.size()];
for(std::vector::iterator iter=ivec...
分类:
编程语言 时间:
2015-05-07 16:55:21
阅读次数:
180
#include
#include
int main()
{
const char *cp1 = "Hello!";
const char *cp2 = "How are you.";
size_t len = strlen(cp1) + strlen(cp2);
char *result = new char[len];
strcpy(result,...
分类:
编程语言 时间:
2015-05-07 16:52:55
阅读次数:
130
#include
#include
int main()
{
const int buf_size = 1024;
char *str1, *str2;
str1 = new char[buf_size];
str2 = new char[buf_size];
std::cin >> str1 >> str2;
int result;...
分类:
编程语言 时间:
2015-05-07 14:34:00
阅读次数:
148
#include
#include
//#include
int main()
{
std::vector ivec(10, 0);
int num;
for(std::vector::iterator iter=ivec.begin(); iter!=ivec.end();
++iter)
{
std::cin >> num...
分类:
编程语言 时间:
2015-05-06 18:03:35
阅读次数:
146