473,386 Members | 1,799 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,386 software developers and data experts.

creating multiple instances of a class dynamically

175 100+
I'm trying to create multiple instances of a class dynamically. For example ...

Expand|Select|Wrap|Line Numbers
  1. Class A
  2. {
  3. ...
  4. ...
  5. };
Expand|Select|Wrap|Line Numbers
  1. Class B
  2. {
  3.     B( int value )
  4.     {
  5.         for( int i = 0; i < value; i++ )
  6.         {
  7.             // I THINK THIS IS RIGHT
  8.             m_a[i] = new A();
  9.         }
  10.     }
  11.     ...
  12.     ...
  13. private:
  14.     // I BELIEVE THIS IS WHERE I'M GOING WRONG
  15.     A** m_a;
  16. ...
  17. ...
  18. };

... I realise what I'm doing is wrong, but I can not remember how to do this. It's been a while since I've had to use c++, and I just can't figure this out. Any help is appreciated.
Apr 15 '11 #1
1 2204
Banfa
9,065 Expert Mod 8TB
Why don't you just use a vector of A in B. In B's constructor you can simple set the vector to the right size.
Apr 18 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ram | last post by:
I have a user control uc (with a dropdownlist uc_dd) that I dynamically add to a pane on a button_click. this pane is hosted on the winform. now when I add two instances of the user control...
9
by: Daz | last post by:
Hello people! (This post is best viewed using a monospace font). I need to create a class, which holds 4 elements: std::string ItemName int Calories int Weight int Density
0
by: John Mott | last post by:
Hello all, I'm trying to break up a large CodeFile .cs file into multiple pieces using partial classes. I'm getting compiler errors which act as if it didn't merge the multiple files. in...
4
by: Mike | last post by:
Class A public objX I want to create 2 or more instances of Class A and have the same value for objX in all instances. Instance1 of Class A Instance2 of Class A Instance3 of Class A
6
by: Bugs | last post by:
Does anyone have any recommendations on the best way to create multiple instances of the same class when the final number of instances is unknown? For example, I have a class and based on some...
5
by: =?Utf-8?B?YjF1Y2VyZWU=?= | last post by:
hi, i need help building multiple instances of an enumerator and naming each one filter1, filter2, filterN depending on how many the user requires, here is the code i have so far public enum...
3
by: yogeshtiwarijbp | last post by:
Hi All I have a resume upload application which is a web application. I have to done load testing on that application. For that i have to create a windows application and create multiple instances...
5
by: pgrazaitis | last post by:
I cant seem to get my head wrapped around this issue, I have myself so twisted now there maybe no issue! Ok so I designed a class X that has a few members, and for arguments sake one of the...
2
LegalIT
by: LegalIT | last post by:
Hello, I have a VB.net application that creates reports from database information. I am able to create the reports fine. The problem is each time I create a report my application starts a new...
6
by: bgremill | last post by:
Hi, all! I have a report with quite a few fields that are hidden and moved depending on if they are tracked by the user or not. The report is previewing and printing just fine. However, my user...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.