473,770 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating multiple instances of a class dynamically

175 New Member
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 2229
Banfa
9,065 Recognized Expert Moderator Expert
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
3045
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 (uc_dd1, uc_dd2), and change the selected item in the dropdown uc_dd1, the selected item in uc_dd2 also changes. any ideas? thank you!
9
2839
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
838
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 doing searches on this problem i saw hints related to setting namespaces on the partial classes but i couldn't get it to work. i had thought that it would work this way:
4
3147
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
6917
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 user actions, I want to create n number instances of those classes, which is obviously unknown at compile time. What is the easiest way to create and then manage these kinds of objects? Using an array seems intuitive but it also seems like it...
5
2109
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 FilterType { None, ADX MOM
3
1370
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 of that form and use that application in the web application using query string or shell script. If some body has any idea abt that plz help. yogesh
5
1737
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 members Y is the location of a file to be read. The original design assumes that this class will be instantiated and each instance will happily mange its own members. (ie One file location per instance...no thread-safety). Now another class A...
2
1657
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 instance of Word instead of just adding a document to the current application. I use the following code to create each report. If I take the New out I get an error. Dim objWord As New Word.Application objWord.Visible = True ...
6
2969
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 wants to be able to open the same report in preview mode for multiple wells selected from a list box. So, one report might have 20 fields visible, and the next might only have 15 fields visible. I can get it to print one right after the other, but...
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.