473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Number at runtime

ikl
class A
{
....
};

For class A, several instances of it could be created, but their number is
unknown until runtime. How to do this?

Thanks!
Jul 22 '05 #1
10 1466

"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
Jul 22 '05 #2

"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
Jul 22 '05 #3
ikl
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);

};

Jul 22 '05 #4
ikl
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);

};

Jul 22 '05 #5
ikl wrote:
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);

};


Member initialization is the constructor's responsibility:

class A
{
vector<B> vec;
public:
A() : vec( n ) {}
}
Jul 22 '05 #6
ikl wrote:
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);

};


Member initialization is the constructor's responsibility:

class A
{
vector<B> vec;
public:
A() : vec( n ) {}
}
Jul 22 '05 #7
ikl <ik***@dsp.com> spoke thus:
John Harrison <jo*************@hotmail.com> wrote in message
news:c5*************@ID-196037.news.uni-berlin.de... When I try it gives error: "error C2061: syntax error : identifier 'n'"
Does anyone know why? Thanks! vector<B> vec(n);


Yep - John wrote "n" to denote that you should replace it with a
number of your choice.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #8
ikl <ik***@dsp.com> spoke thus:
John Harrison <jo*************@hotmail.com> wrote in message
news:c5*************@ID-196037.news.uni-berlin.de... When I try it gives error: "error C2061: syntax error : identifier 'n'"
Does anyone know why? Thanks! vector<B> vec(n);


Yep - John wrote "n" to denote that you should replace it with a
number of your choice.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #9
ikl

Jon Willeke <j.***********@verizon.dot.net> wrote in message
news:9m******************@nwrdny03.gnilink.net...
ikl wrote:
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);

};


Member initialization is the constructor's responsibility:

class A
{
vector<B> vec;
public:
A() : vec( n ) {}
}


Why have to use constructor to initialize "vec"? Why not just like,

class B
{
int Number[10];
};

and don't need to initialize with "10"?

Thanks!


Jul 22 '05 #10
ikl

Jon Willeke <j.***********@verizon.dot.net> wrote in message
news:9m******************@nwrdny03.gnilink.net...
ikl wrote:
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);

};


Member initialization is the constructor's responsibility:

class A
{
vector<B> vec;
public:
A() : vec( n ) {}
}


Why have to use constructor to initialize "vec"? Why not just like,

class B
{
int Number[10];
};

and don't need to initialize with "10"?

Thanks!


Jul 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Charles | last post by:
Is there a way to obtain the line number in my code? For example: 1 public class MyClass { 2 int a = 5; 3 System.out.println("Integer variable a was set on line number: " + x); 4 etc....
8
by: EAS | last post by:
Hey, I'm new to python (and programming in general) so I'll prolly be around here a lot... Anyways, I've found out how to make a "guess my number game" where the player guesses a number between...
7
by: PW | last post by:
I'm trying to interrogate an incoming value from a previous ASP like this .... myCurrentQty = request.querystring("txtBCQty" & myRecordCounter) It returns a "2" as expected. But if I try to...
7
by: Snyke | last post by:
Well my problem is simple: I have a class which has a variable number of members. Lets say I have a class Family and a variable number of FamilyMembers. Until now I used a member of Family called...
8
by: Mark | last post by:
I have it in my head that I saw a marketing document from Microsoft with the total number of classes and methods in the .NET Framework. Something like 70,000 methods? I don't need precise numbers,...
2
by: Colin Hale | last post by:
Hi, I've got a legacy ATL component which throws errors using the ATL Error() function. I have always handled these errors in VB6 using on error goto, then in the error handling code I could...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
9
by: Adrienne Boswell | last post by:
I am getting this error: Error Type: Microsoft VBScript runtime (0x800A000D) Type mismatch: 'sid' /beta/files/index.asp There is no line number, and there is absolutely nothing on that page...
5
by: imailz | last post by:
Hi all, since I'm forced to switch from Fortran to C I wonder if there is posibility in C: 1) to use implicit loops 2) to parse several variables which number is determined at runtime. ...
10
by: Matthias | last post by:
Dear newsgroup. I want to write a template function which accepts either integer or floating point numbers. If a certain result is not a whole number and if the template parameter is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.