运行时的数字 [英] Number at runtime
问题描述
A级
{
....
};
上课A,可以创建它的几个实例,但它们的数量在运行时间之前是未知的。怎么做?
谢谢!
" IKL" < IK *** @ dsp.com>在消息中写道
news:6B ******************** @ bgtnsc05-news.ops.worldnet.att.net ... < blockquote class =post_quotes> A级
{
...
};
对于A类,可以创建它的几个实例,但它们的编号在运行时之前是未知的。怎么做?
使用矢量。
#include< vector>
>
std :: vector< A> VEC(N); //创建n个对象
john
" ikl" < IK *** @ dsp.com>在消息中写道
news:6B ******************** @ bgtnsc05-news.ops.worldnet.att.net ... < blockquote class =post_quotes> A级
{
...
};
对于A类,可以创建它的几个实例,但它们的编号在运行时之前是未知的。怎么做?
使用矢量。
#include< vector>
>
std :: vector< A> VEC(N); //创建n个对象
john
John Harrison< jo *********** **@hotmail.com>在消息中写道
news:c5 ************* @ ID-196037.news.uni-berlin.de ...
ikl < IK *** @ dsp.com>在消息中写道
新闻:6B ******************** @ bgtnsc05-news.ops.worldnet.att.net ...A级
{
...
};
对于A类,可以创建它的几个实例,但它们的数量为
直到运行时才知道。怎么做?
使用矢量。
#include< vector>
std :: vector< A> VEC(N); //创建n个对象
john
当我尝试它时会出现错误:错误C2061:语法错误:标识符''n ''"
有谁知道为什么?谢谢!
#include< vector>
使用std :: vector;
B级
{
};
int n = 1;
A级
{
vector< B> vec(n);
};
class A
{
....
};
For class A, several instances of it could be created, but their number is
unknown until runtime. How to do this?
Thanks!
"ikl" <ik***@dsp.com> wrote in message
news:6B********************@bgtnsc05-news.ops.worldnet.att.net...class A
{
...
};
For class A, several instances of it could be created, but their number is
unknown until runtime. How to do this?
Use a vector.
#include <vector>
std::vector<A> vec(n); // creates n A objects
john
"ikl" <ik***@dsp.com> wrote in message
news:6B********************@bgtnsc05-news.ops.worldnet.att.net...class A
{
...
};
For class A, several instances of it could be created, but their number is
unknown until runtime. How to do this?
Use a vector.
#include <vector>
std::vector<A> vec(n); // creates n A objects
john
John Harrison <jo*************@hotmail.com> wrote in message
news:c5*************@ID-196037.news.uni-berlin.de...
"ikl" <ik***@dsp.com> wrote in message
news:6B********************@bgtnsc05-news.ops.worldnet.att.net...class A
{
...
};
For class A, several instances of it could be created, but their number is unknown until runtime. How to do this?
Use a vector.
#include <vector>
std::vector<A> vec(n); // creates n A objects
john
When I try it gives error: "error C2061: syntax error : identifier ''n''"
Does anyone know why? Thanks!
#include <vector>
using std::vector;
class B
{
};
int n = 1;
class A
{
vector<B> vec(n);
};
这篇关于运行时的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!