hello,
with
struct C
{
string f1;
};
class A
{
C data;
};
what is the best way to pass member pointer to f1
relative to class A, sth. like "&A::data.f 1" ?
---- backgroud:
i'd like to compose classes in following way:
--- generic part ---
// carry some data
class field
{ ...
};
// keep information on (contained) fields
class record_definiti on
{ ...
};
// and perform common actions
class record
{
shared_ptr<reco rd_definition> recdef;
public:
record(shared_p tr<record_defin ition> _recdef) : recdef(_recdef) ...
...
};
---- user's part ----
// here is the data struct
struct data_t
{
field f1;
field f2;
...
};
// here, the data_t is enhanced with
// functionality from record
// my_record provides record definition
// so class record has acces to the fields
class my_record : public record
{
protected: // but could be public as well
data_t data;
};
----
my_record would pass pointers to member's member fields
f1, f2 etc.
TIA,
georg 1 1524
Georg D. wrote: with
struct C { string f1; };
class A { C data; };
what is the best way to pass member pointer to f1 relative to class A, sth. like "&A::data.f 1" ?
A pointer-to-member is just that. You can't make one point to a member
of a member. You have to simulate that with two pointers-to-member.
struct string { };
struct C
{
string f1;
};
class A
{
public:
C data;
};
struct pmm
{
pmm (C A::* p, string C::* q) : p (p), q (q) { }
string & dereference_on (A & a) { return a.* p.* q; }
private:
C A::* p;
string C::* q;
};
int main ()
{
A a;
pmm p (& A::data, & C::f1);
string x = p.dereference_o n (a);
// You can overload operators to get "x = a * p", or "x = p (a)", or
// something else, but you cannot get "x = a.* p".
}
--
Regards,
Buster. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Newsgroup - Ann |
last post by:
Gurus,
I have the following implementation of a member function:
class A
{
// ...
virtual double func(double v);
void caller(int i, int j, double (* callee)(double));
void foo() {caller(1, 2, func);
|
by: Ben |
last post by:
Hi, there.
Recently I was working on a problem where we want to save generic
closures in a data structure (a vector). The closure should work for
any data type and any method with pre-defined signature.
When developing this lib, I figured that the
pointer-to-member-function, although seemingly an attractive solution,
does not work well for us.
|
by: Steve Rencontre |
last post by:
I can't for the life of me see how to do pointer-to-member when the
member is actually part of an embedded structure.
That is, if I have:
struct S1 { int a; };
struct S2 { S1 s; int b; };
how can I get a pointer to the a in an S2?
|
by: WaterWalk |
last post by:
Hello. I am rather confused by the type of a pointer to class data
member. Many c++ texts say that pointer to data member has a special
syntax. For example the following class:
class MyClass
{
public:
int n;
};
The pointer to MyClass.n shall be defined like this:
|
by: WaterWalk |
last post by:
Hello. I thought I understood member function pointers, but in fact I
don't. Consider the following example:
class Base
{
public:
virtual ~Base() {}
};
class Derived : public Base
{
| |
by: Tim Frink |
last post by:
Hi,
I'm experimenting with function pointers and found
two questions. Let's assume this code:
1 #include <iostream>
2 class A;
3
4 ////////////////////////////////////////////
5 class B
|
by: huili80 |
last post by:
Say I have two classes:
class A
{
public:
int x;
};
class B
{
|
by: Immortal Nephi |
last post by:
I would like to design an object using class. How can this class
contain 10 member functions. Put 10 member functions into member
function pointer array.
One member function uses switch to call 10 member functions. Can
switch be replaced to member function pointer array?
Please provide me an example of source code to show smart pointer
inside class. Thanks....
|
by: Immortal_Nephi |
last post by:
I had a lot of research to see how function pointer works. Sometimes,
programmers choose switch keyword and function in each case block can
be called. Sometimes, they choose ordinary function pointer array
instead of switch.
They believe that ordinary function pointer is much faster than
switch. Think of one variable called selectFunction. selectFunction
variable can be the range of 0 through 1,000 or more.
Load selectFunction...
|
by: ghulands |
last post by:
I am having trouble implementing some function pointer stuff in c++
An object can register itself for many events
void addEventListener(CFObject *target, CFEventHandler callback,
uint8_t event);
so I declared a function pointer like
typedef void (CFObject::*CFEventHandler)(CFEvent *theEvent);
|
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: 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,...
|
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: 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: 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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |