473,545 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

great c++ question

implement a c++ class such that it allows us
to add data members at runtime.

Jun 21 '07 #1
29 1976
Amar Kumar Dubedy wrote:
implement a c++ class such that it allows us
to add data members at runtime.
Here's a great answer, impossible.
I think Coplien has some code that *simulates* this in 'Advanced C++
Programming Styles and Idioms'.

john
Jun 21 '07 #2
On Jun 21, 6:48 am, Amar Kumar Dubedy <adub...@yahoo. co.inwrote:
implement a c++ class such that it allows us
to add data members at runtime.
Who in the world would want that?

Jun 21 '07 #3
On Jun 21, 10:50 am, John Harrison <john_androni.. .@hotmail.com>
wrote:
Amar Kumar Dubedy wrote:
implement a c++ class such that it allows us
to add data members at runtime.

Here's a great answer, impossible.

I think Coplien has some code that *simulates* this in 'Advanced C++
Programming Styles and Idioms'.

john
I thought that it was impossible too. But its a question asked in
Yahoo Interview. So i thought i wud put it up.

Jun 21 '07 #4
am**********@ya hoo.co.in wrote:
On Jun 21, 10:50 am, John Harrison <john_androni.. .@hotmail.com>
wrote:
>Amar Kumar Dubedy wrote:
>>implement a c++ class such that it allows us
to add data members at runtime.
Here's a great answer, impossible.

I think Coplien has some code that *simulates* this in 'Advanced C++
Programming Styles and Idioms'.

john

I thought that it was impossible too. But its a question asked in
Yahoo Interview. So i thought i wud put it up.
Sounds like a trick question.
Jun 21 '07 #5
Amar Kumar Dubedy wrote:
implement a c++ class such that it allows us
to add data members at runtime.
sure it's possible, still you need to access them, and know their types. all
feasible.
a void pointer kan be used, or if you know the type you can make an abstract
base class and inherit classes from that. save in whatever for later
access. Still, as I see it there needs to be some kind of "known" interface
that you can use for accessing.
Jun 21 '07 #6
Bobba Dobba wrote:
Amar Kumar Dubedy wrote:
>implement a c++ class such that it allows us
to add data members at runtime.
sure it's possible, still you need to access them, and know their types. all
feasible.
a void pointer kan be used, or if you know the type you can make an abstract
base class and inherit classes from that. save in whatever for later
access. Still, as I see it there needs to be some kind of "known" interface
that you can use for accessing.
Show us some code. I don't see how anything you've said above relates to
adding data members at runtime.

john
Jun 21 '07 #7
John Harrison wrote:
Bobba Dobba wrote:
>Amar Kumar Dubedy wrote:
>>implement a c++ class such that it allows us
to add data members at runtime.
sure it's possible, still you need to access them, and know their types.
all feasible.
a void pointer kan be used, or if you know the type you can make an
abstract base class and inherit classes from that. save in whatever for
later access. Still, as I see it there needs to be some kind of "known"
interface that you can use for accessing.

Show us some code. I don't see how anything you've said above relates to
adding data members at runtime.

john
depends on where you save them, stack, list, vector. a data member can also
be embedded in a abstract class, which you derive a specialised class from.
so, my idea is that the cotnainer used for storing the dynamic data members
would be "compiled in". but the contents would not. well, try it*S*
Jun 21 '07 #8
John Harrison wrote:
Bobba Dobba wrote:
>Amar Kumar Dubedy wrote:
>>implement a c++ class such that it allows us
to add data members at runtime.
sure it's possible, still you need to access them, and know their
types. all
feasible.
a void pointer kan be used, or if you know the type you can make an
abstract
base class and inherit classes from that. save in whatever for later
access. Still, as I see it there needs to be some kind of "known"
interface
that you can use for accessing.

Show us some code. I don't see how anything you've said above relates to
adding data members at runtime.
Data members have a type, and a name, they are accessed with a
particular syntax. All of these are features of source code, not of a
running program. The question doesn't amke sense unless it is a trick
question.

Of course of the question had been, 'write a class so that you can add
arbitrary data at runtime' it would be much easier. But the question
said data members, not data.
Jun 21 '07 #9
Bobba Dobba wrote:
John Harrison wrote:
>Bobba Dobba wrote:
>>Amar Kumar Dubedy wrote:

implement a c++ class such that it allows us
to add data members at runtime.
sure it's possible, still you need to access them, and know their types.
all feasible.
a void pointer kan be used, or if you know the type you can make an
abstract base class and inherit classes from that. save in whatever for
later access. Still, as I see it there needs to be some kind of "known"
interface that you can use for accessing.
Show us some code. I don't see how anything you've said above relates to
adding data members at runtime.

john
depends on where you save them, stack, list, vector. a data member can also
be embedded in a abstract class, which you derive a specialised class from.
so, my idea is that the cotnainer used for storing the dynamic data members
would be "compiled in". but the contents would not. well, try it*S*

Add data to a vector is adding data to an object. It is not the same
thing at all as adding a data member to a class. For instance if you add
a data member to a class, then ALL objects of that class get the new
data member.

class X
{
int d;
};

d is a data member, now how at runtime do I change the code so that X
becomes

class X
{
int d;
int d2;
};

The obvious problem is that X only exists in the source code of the
program. This is not true of all programming languages, but it is true
of C++.
Jun 21 '07 #10

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

Similar topics

11
2059
by: John Wellesz | last post by:
Hello, It would be great if there was an option to tell PHP to let the user manage all the HTTP headers instead of sending what it thinks is good for the programmer... For example when you write: header("Status: 200 OK"); header("Location: /my_internal_redirected_page.php");
5
1350
by: Electrified Research | last post by:
>From ASP.NET 1.1 I have a very useful UserControl which acts like a template control. I call it a CustomTemplate. Basically it gives me a re-usable look to sections of the site without having to tinker with HTML. This is very much like what is being done by Master Pages but with a User Control. I have a two part question: 1. Is there...
5
282
by: Chris | last post by:
Hey all. Anyone who is familiar with Python programming knows that you can have code like this: list = This code puts all the items processed by the for loop in a list plus 1. Is there a way to do this in C++? Something like: int list = { x + 1 for (int x = 0; x < 5; x++); } Or something?
1
1301
by: Alex | last post by:
Hello, On Wednesday, Feb 1 at 2pm PST Microsoft will be hosting a webcast for Microsoft ISV Partners, or those considering becoming an ISV Partner. The webcast will be presented by the Microsoft ISV Advisory Services team who will discuss the great value and benefits available for Microsoft developers. Please join us for the webcast by...
1
1644
by: flit | last post by:
Hi all, I had one problem with csv files. And I put the message on 2 microsoft board and in this group. Results: No response from microsoft, and always 3 responses for posts on this lists. I just want to say thank you for all.
32
2482
by: Tom Cole | last post by:
I bet 50% of the posts I've read lately have had at least one bad thing to say about every website or book dedicated to javascript. There are clearly a few posters (you know who you are) who either are or consider themselves to be the "comp.land.javascript elite". You guys may be the brightest, most seasoned developers out there, and hats...
42
2217
by: gt8887b | last post by:
Hello! In his recent newsletter embedded expert Jack Ganssle says that programming students, as well as professional developers should readh "great code" (hight quality/well-crafted code that works). He even gives to examples. One is uC/OS-II operating system and the other is TCP/IP stack for said system. Do you know of other good...
14
1700
by: Alfred Sehmueller | last post by:
Hello, we were in contact with the microsoft licence hotline last week. We want to build a asp.net application based upon a windows 2003 server and Microsoft sql-server 2005. It will be a commerical application for customers. The question was which microsoft licences are required on the customer site. The technology: ASP.NET, One central...
11
1981
by: Jang | last post by:
Does anyone have an example of well written JavaScript applications that they know about? I would prefer the code to be readable. I particularly like YUI's code. Does anyone have any more applications/ examples? Thanks .
0
7484
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...
0
7415
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...
0
7928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7440
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...
1
5344
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...
0
4963
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...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1902
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
726
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...

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.