If I'm not mistaken, C++ doesn't have support for dynamic class
members. I'm considering if such a facility would be useful, and what
method would make a good workaround.
I have a generic buffer class, which can have one or more cursor
classes attached to it. Right now, they are both separate classes,
and I use them as follows:
class Buffer {
...
}
class Cursor {
...
}
pBuffer = new Buffer;
pCursor = pBuffer->CreateCursor() ;
pCursor->Insert();
....
pBuffer->DestroyCursor( pCursor);
The parent buffer of pCursor is implicit at the Insert() call, when it
would preferably be explicit. A cleaner facility might be to create a
dynamic member for each cursor. Below, the parameter to CreateCursor
is the new name of the dynamic member, and the function knows the type
to which it must be initialized. The syntax
"pBuffer->pCursor->Insert()" would trigger an overridable lookup and
dispatch function in the buffer class, followed by the Insert()
function of the particular cursor instance.
pBuffer = new Buffer;
pBuffer->CreateCursor(" pCursor");
pBuffer->pCursor->Insert();
....
pBuffer->DestroyCursor( "pCursor");
The only way I can think of to achieve this kind of behavior, short of
importing some specialized non-standard library, is to use handles, C
style. Statement (2) below was actually my original technique, but
then the cursor and buffer code was intermingled.
pBuffer = new Buffer;
HANDLE pCursor;
pCursor = pBuffer->CreateCursor() ;
(1) pBuffer->GetCursor(pCur sor)->Insert();
-OR-
(2) pBuffer->Insert(pCursor );
....
pBuffer->DestroyCursor( pCursor);
The drawback of the handle technique is that handles must be
maintained outside of the class, but it is fast because the handles
can be the indexes into the cursor class instance pointers array. I
suppose I could create a hash table for cursor names, and then refer
to them using the string name, like this:
pBuffer = new Buffer;
pBuffer->CreateCursor(" MyCursor");
pBuffer->GetCursor("MyC ursor")->Insert();
....
pBuffer->DestroyCursor( "MyCursor") ;
I like this solution, but there is performance overhead of using a
hash table to lookup the class instance for the given string at
runtime. Anyway, I'm just writing to clarify my thoughts. I will
probably use the split class method I outlined first just for its low
overhead. If you have any comments, feel free to reply. 0 1567 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Felix I. Wyss |
last post by:
Good Afternoon,
I recently noticed that some very simple methods of a template declared and
used in a DLL library get inlined when used by the DLL itself, but not by
other DLLs and EXEs. After some investigating, I narrowed this down to a
very odd behavior (bug?) of the VC++.NET 2003 compiler: If a class that is
declared as __declspec(dllimport) derives from a template, that template's
methods are never inlined, even if declared with...
|
by: twawsico |
last post by:
I ran into this while converting some DX C# code to VB.NET (VS 2003),
and I'm just curious as to whether this is intended behavior (and if
so, where might I read up on it) or more of a bug.
This involves creating a New instance of a derived class that inherits
a base class. In C#, private member vars in the derived class ( e.g.
private MySimpleObject MyObject = new MySimpleObject();) are
instantiated immediately when the the calling code...
|
by: rwf_20 |
last post by:
I just wanted to throw this up here in case anyone smarter than me has
a suggestion/workaround:
Problem:
I have a classic producer/consumer system which accepts 'commands' from
a socket and 'executes' them. Obviously, each different command (there
are ~20 currently) has its own needed functionality. The dream goal
here would be to remove all knowledge of the nature of the command at
runtime. That is, I don't want ANY switch/cases...
|
by: msaladin |
last post by:
Hi all,
I spent today with finding an error, I found it, though I don't no why.
I have a class with static constants, like this:
class EXPORT_API BusConstants {
public:
static const std::string PIPE_DIRECTORY;
};
|
by: Mark S. |
last post by:
As I understand it, C# doesn't offer dynamic variable names. Below is my
attempted workaround. Is what I'm doing possible?
FYI, I already read all the "why in the world do you need dynamic variabale
names" comments by other posters, if you are kind enough to post a reply
please either say it's impossible, or it is possible if I did x. TIA
using System;
namespace ConsoleForTesting
| |
by: Daniel Lidström |
last post by:
Hello!
I have just discovered a way to use the private implementation idiom
(pimpl), without the overhead of dynamic memory allocation. For those of
you who don't know what this is, Wikipedia has a nice article you can
read. Anyway, I discovered that if you make all members in the
implementation class mutable, you can in fact use this idiom without any
"unnecessary" memory allocation. Here's a minimal example of the method:
// In the...
|
by: EDBrian |
last post by:
My problem is this. Our clients create different fields they want to
collect and we allow them build dynamic filters, reports etc...
We run some TSQL to actually create the column and all works very well. We
are now adding a lot more functionality to our filters and could really
benefit from using the LINQ to SQL.
I have experimented with the Dynamic Linq...
|
by: subramanian100in |
last post by:
Consider the following classes without ctors.
class Sample
{
private:
double d_val;
double* d_ptr;
};
class Test
|
by: santiagofs |
last post by:
Hi, I want to know if it is any workaround for this:
I have a class which models a database table behavior (table abstract class)
I have several clases wich extends the table abstract class, providing information about their fields. The name of this classes are the names of the tables on the database. (users, stock, sales, etc)
I want to have a class wich provide additional functionality to each the users, stock, sales, etc, and define it...
|
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...
|
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...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |