关于对象的问题 [英] Question about objects

查看:71
本文介绍了关于对象的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有人可以向我解释,为什么在

下面的代码第二种方法不起作用?


感谢您的帮助。

#include< vector>


class Base {};


class继承:public Base {};


void foo(std :: vector< Basearg){}


void main (){

std :: vector< Inheritedv1;

v1.push_back(Inherited());


//工作

std :: vector< Basev2;

for(int i = 0; i< v1.size(); v2.push_back(v1 [i ++]));

foo(v2);


//无法工作

foo(v1);

}

Hi,

could someone please explain to me, why in the
following code the second approach does not work?

Thanks for your help.
#include <vector>

class Base {};

class Inherited : public Base{};

void foo(std::vector<Basearg) {}

void main() {
std::vector<Inheritedv1;
v1.push_back(Inherited());

// does work
std::vector<Basev2;
for(int i=0; i<v1.size(); v2.push_back(v1[i++]));
foo(v2);

// doesn''t work
foo(v1);
}

推荐答案

R2D2写道:
R2D2 wrote:




有人可以向我解释,为什么在

下面的代码第二种方法不起作用?


感谢您的帮助。


#include< v ector>


class Base {};
Hi,

could someone please explain to me, why in the
following code the second approach does not work?

Thanks for your help.
#include <vector>

class Base {};



因为它是C ++,这是一个C新闻组。


尝试comp.lang.c ++。当你在那里发布它时,将

main()的返回类型更改为int,并解释你的意思是不起作用。


Brian

Because it''s C++, and this is a C newsgroup.

Try comp.lang.c++. When you post it there, change the return type of
main() to int, and explain what you mean by "does not work".

Brian


On 2007-08-28 19:13:17 -0400," Default User" < de *********** @ yahoo.comsaid:
On 2007-08-28 19:13:17 -0400, "Default User" <de***********@yahoo.comsaid:

R2D2写道:
R2D2 wrote:

>

有人可以向我解释,为什么在
下面的代码第二种方法不起作用?

谢谢你的帮助。

#include< vector>

class Base {};
>Hi,

could someone please explain to me, why in the
following code the second approach does not work?

Thanks for your help.
#include <vector>

class Base {};



因为它是C ++,而且这是一个C新闻组。


Because it''s C++, and this is a C newsgroup.



对于某些未指定的值this。我没有读过comp.lang.c,但是我在读取comp.lang.c ++时读到了b $ b,这就是我正在阅读这条消息的地方。


-

Pete

Roundhouse Consulting,Ltd。( www.versatilecoding.com

标准C ++库扩展:一个教程和参考的作者

www.petebecker.com/tr1book

For some unspecified value of "this". I don''t read comp.lang.c, but I
do read comp.lang.c++, and that''s where I''m reading this message.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)


R2D2写道:
R2D2 wrote:




有人可以向我解释,为什么在

以下代码第二种方法不起作用?


感谢您的帮助。


#include< vector>


class Base {};


class Inherited:public Base {};
Hi,

could someone please explain to me, why in the
following code the second approach does not work?

Thanks for your help.
#include <vector>

class Base {};

class Inherited : public Base{};



继承是一种基础;
http://www.parashift.com/c++-faq-lit....html#faq-19.3


但是


std :: vector< Inherited不是std :: vector< Base>
http://www.parashift.com/c++-faq-lit .... html#faq-21.3


LR

Inherited is a kind of Base;
http://www.parashift.com/c++-faq-lit....html#faq-19.3

But

std::vector<Inheritedis not a std::vector<Base>
http://www.parashift.com/c++-faq-lit....html#faq-21.3

LR


这篇关于关于对象的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆