473,624 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is this possible?

Kev
Hi, lets see if I can explain this right. :o)

Lets say I wish to change several variables nested multiple classes deep.
The usual way I figure is to just say "class#.struct. a (b,c...) =
somenumbers;". Is there a way to preset "class#' at the beginning of the
function its passed to so that I can just say 'struct.a (b,c) = numbers'
and "class#' is assumed?

cheers
Jul 23 '05 #1
8 1304
"Kev" <di************ **@pht.zzz> wrote in message
news:Xn******** **************@ 216.168.3.44...
Hi, lets see if I can explain this right. :o)

Lets say I wish to change several variables nested multiple classes deep.
The usual way I figure is to just say "class#.struct. a (b,c...) =
somenumbers;".
I'm assuming you really mean multiple _objects_ deep.
Is there a way to preset "class#' at the beginning of the
function its passed to so that I can just say 'struct.a (b,c) = numbers'
and "class#' is assumed?


Only if the function is a non-static member function of the class of which
the object class# is an instance.

DW
Jul 23 '05 #2
"Kev" <di************ **@pht.zzz> wrote in message
news:Xn******** **************@ 216.168.3.44
Hi, lets see if I can explain this right. :o)

Lets say I wish to change several variables nested multiple classes
deep. The usual way I figure is to just say "class#.struct. a (b,c...)
= somenumbers;". Is there a way to preset "class#' at the beginning
of the function its passed to so that I can just say 'struct.a (b,c)
= numbers' and "class#' is assumed?

cheers


Given an outer object (or a reference or pointer to it), you can create a
reference (or pointer) to an inner object, e.g.,
struct Outer
{
struct Inner
{
struct DoubleInner
{
int a, b, c;
};
DoubleInner doubleinner;
};
Inner inner;
};

void Setabc(Outer &o)
{
Outer::Inner::D oubleInner & shortcut = o.inner.doublei nner;
shortcut.a = 1;
shortcut.b = 2;
shortcut.c = 3;
}

The other way to do it is to make Setabc take a reference to DoubleInner as
its argument:

void Setabc(Outer::I nner::DoubleInn er &di)
{
di.a = 1;
di.b = 2;
di.c = 3;
}

You would then have to supply, say, o.inner.doublei nner as an argument to
the function.

--
John Carson

Jul 23 '05 #3

"Kev" <di************ **@pht.zzz> schrieb im Newsbeitrag
news:Xn******** **************@ 216.168.3.44...
Hi, lets see if I can explain this right. :o)

Lets say I wish to change several variables nested multiple classes
deep.
The usual way I figure is to just say "class#.struct. a (b,c...) =
somenumbers;". Is there a way to preset "class#' at the beginning of
the
function its passed to so that I can just say 'struct.a (b,c) =
numbers'
and "class#' is assumed?


class A
{
public:
int m;
};
class B
{
public:
double m;
}
template <class C> changeM(C* pC)
{
pC->m = 0;
}

int main()
{
A a; B b;
changeM(&a);
changeM(&b);
}

Is this what you want??
Jul 23 '05 #4
Kev
"John Carson" <jc************ ****@netspace.n et.au> wrote in news:daii34
$1*****@otis.ne tspace.net.au:
void Setabc(Outer &o)
{
Outer::Inner::D oubleInner & shortcut = o.inner.doublei nner;
shortcut.a = 1;
shortcut.b = 2;
shortcut.c = 3;
}


Would this work if Outer could represent more than one classtype, but
sharing the same base? Perhaps using the base classname instead? Similar to
using a base pointer for a derived class? In this case DoubleInner would be
in the base, common to all.

Base::Inner::Do ubleInner &shortcut ?
Jul 23 '05 #5
"Kev" <di************ **@pht.zzz> wrote in message
news:Xn******** **************@ 216.168.3.44
"John Carson" <jc************ ****@netspace.n et.au> wrote in
news:daii34 $1*****@otis.ne tspace.net.au:
void Setabc(Outer &o)
{
Outer::Inner::D oubleInner & shortcut = o.inner.doublei nner;
shortcut.a = 1;
shortcut.b = 2;
shortcut.c = 3;
}


Would this work if Outer could represent more than one classtype, but
sharing the same base? Perhaps using the base classname instead?
Similar to using a base pointer for a derived class? In this case
DoubleInner would be in the base, common to all.


Do you mean the class DoubleInner or the variable doubleinner or both? If
Outer is a base class, say:

struct Derived1 : public Outer
{
// stuff
};

struct Derived2 : public Outer
{
// stuff
}

and we have an instance of a derived class:

Derived1 d1;

then we can call the original function with no change:

Setabc(d1);

All the action is in the base class and the fact that it is derived from is
irrelevant.

The more general point is this: if you can get access to member variables
within the function via a series of objects/pointers:

a.b->c.d.e->f.g.member1
a.b->c.d.e->f.g.member2
a.b->c.d.e->f.g.member3

then you can produce a shortcut with which to access members 1-3 as follows:

A::B::C::D::E:: F::G & shortcut = a.b->c.d.e->f.g;

where A is the type of a, B* is the type of b, C is the type of c and so on.

You then call it with

shortcut.member 1
shortcut.member 2
shortcut.member 3

If the last thing in the original chain before the members is a pointer
rather than an object, i.e.,

a.b->c.d.e->f.g->member1
a.b->c.d.e->f.g->member2
a.b->c.d.e->f.g->member3

then the definition of shortcut changes via the addition of an asterisk so
that it becomes a reference to a pointer:

A::B::C::D::E:: F::G *& shortcut = a.b->c.d.e->f.g;

(note that pointers earlier in the chain affect the right-hand side of the
assignment, but not the left-hand side; by contrast, if the final thing in
the chain is a pointer, it affects the left-hand side but not the right-hand
side). You use shortcut as follows:

shortcut->member1
shortcut->member2
shortcut->member3

You can also transform a pointer into a reference or a reference into a
pointer. This is left as an exercise for the reader.

--
John Carson

Jul 23 '05 #6
Kev
"John Carson" <jc************ ****@netspace.n et.au> wrote in news:dal1e5
$2*****@otis.ne tspace.net.au:
A::B::C::D::E:: F::G & shortcut = a.b->c.d.e->f.g;


I get compiler errors with A::B saying that B is not a member of A. So...
Im sure Im making some 'bite me in the ass' mistake someplace that I will
find ;o)

I appreciate everyones efforts and sharing different ways to figure this
out. After reading further using 'namespace' in some more elaborate ways
might offer something. But I might have misunderstood and need to read
further.

cheers all!!!
Jul 23 '05 #7
"Kev" <di************ **@pht.zzz> wrote in message
news:Xn******** *************@2 16.168.3.44
"John Carson" <jc************ ****@netspace.n et.au> wrote in
news:dal1e5 $2*****@otis.ne tspace.net.au:
A::B::C::D::E:: F::G & shortcut = a.b->c.d.e->f.g;


I get compiler errors with A::B saying that B is not a member of A.
So... Im sure Im making some 'bite me in the ass' mistake someplace
that I will find ;o)


My description assumes that B is a class/struct nested inside A, that C is a
class/struct nested inside B and so on. Taking a two struct case for
simpliciy, if, say, you had this scenario:

struct B
{
int member1, member2;
};

struct A
{
B b;
};

Then clearly given

A a;

a.b gives you an object of B, not an object of A::B. Thus you would use:

B & shortcut = a.b;

shortcut.member 1
shortcut.member 2

Basically, given

a.b->c.d.e->f.g.member1

you have to figure out the type of g. You then declare:

Type_of_g & shortcut = a.b->c.d.e->f.g;
--
John Carson

Jul 23 '05 #8
Kev
"John Carson" <jc************ ****@netspace.n et.au> wrote in news:dalc5p
$2*****@otis.ne tspace.net.au:
you have to figure out the type of g. You then declare:

Type_of_g & shortcut = a.b->c.d.e->f.g;


Apologies, was away for awhile. After thinking about the problem I really
was making it more difficult than I needed to. Many things just werent in
the right place to begin with. The shortcut ideas are less complicated,
done a little differently, and work nicely.

Thank you :o)

Theres another puzzler about stl::list, and also something Im going about
the wrong way Im sure. But thats another post :o)
Jul 23 '05 #9

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

Similar topics

4
14466
by: Julia Briggs | last post by:
I am struggling to create a PHP function that would take a specified image (JPG, GIF or PNG) from a link, and resize it down to a thumbnail so it will always fit in a 200x250 space. I am hoping not to have it inserted or read from a database to do this function. Can it be done & someone please help me?
36
9454
by: rbt | last post by:
Say I have a list that has 3 letters in it: I want to print all the possible 4 digit combinations of those 3 letters: 4^3 = 64 aaaa
20
2475
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to the site, and then i have to select the file to upload.. i used sendkeys.. and i worked perfect.. BUT ... the computer must be locked for security ( obviusly ) reazons.. so..i think this probable solutions to unlock the computer and run the...
7
2342
by: Andrzej | last post by:
Is it possible to call a function which name is given by a string? Let assume that I created a program which call some functions for example void f1(void), void f2(void), void f3(void). After some time, I added new function void f4(void).
2
3800
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens provide text area where the user can insert big chunks of text and submit it all to the server paragraph by paragraph. The requirement is to do a Spell Check AND Grammar Check in the text area. I did look at lot of possible third
1
6952
by: AAA | last post by:
hi, I'll explain fastly the program that i'm doing.. the computer asks me to enter the cardinal of a set X ( called "dimX" type integer)where X is a table of one dimension and then to fill it with numbers X; then the computer asks me how many subsets i have (nb_subset type (integer)) then,i have to enter for every sebset the card, and then to fill it, we'll have a two tables , one called cardY which contains nb_subset elements,and every...
25
2536
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e. every 5 seconds, i just want to refresh it ONLY on server change just like desktop applications do. The problem is that refreshing evry n seconds has to much impact on my web server. The refresh action should be taken only when something
4
7672
by: RSH | last post by:
Okay my math skills aren't waht they used to be... With that being said what Im trying to do is create a matrix that given x number of columns, and y number of possible values i want to generate a two dimensional array of all possible combinations of values. A simple example: 2 - columns and 2 possible values would generate: 0 0
7
3351
by: Robert S. | last post by:
Searching some time now for documents on this but still did not find anything about it: Is it possible to replace the entry screen of MS Office Access 2007 - that one presenting that default 'templates' (with that big graphic buttons) - with some sort of own HTML-Page? I could imagine, that somehow it is possible to change this construction (hopefully not hardcoded in MS-Acc07), like it is possible to edit the 'Fluent Ribbon'? If so...
14
1996
by: bjorklund.emil | last post by:
Hello pythonistas. I'm a newbie to pretty much both programming and Python. I have a task that involves writing a test script for every possible combination of preference settings for a software I'm testing. I figured that this was something that a script could probably do pretty easily, given all the various possibilites. I started creating a dictionary of all the settings, where each key has a value that is a list of the possible...
0
8177
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
8629
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7170
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
6112
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
5570
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();...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
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
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
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.