473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

creating alias for a class object

KK
Hi,
How can I create alias for a class object? Please go thru this
program to understand the motivation.

Class Name;
Class Country{
Name list[10];
/*My intension is to have:
list[0] - usa
list[1] - uk
list[2] - ..
*/
//define other essential member functions
void PrintMyself (void );
}
void Country::PrintMyself()
{
for (int i=0;i<10;i++)
//print the entire array :: makes my life so easy with
indexing
}
void somefunc(Country& ex)
{
Name usa_country;
usa_country =ex.list[0]; //indexing is no good here - I wish I had
the alias for list[0] as usa
}
Hoping to get the answer.
Thank you.
KK

Nov 22 '05 #1
2 2128
KK wrote:
Hi,
How can I create alias for a class object? Please go thru this
program to understand the motivation.

Class Name;
Class Country{
Name list[10];
/*My intension is to have:
list[0] - usa
list[1] - uk
list[2] - ..
*/
//define other essential member functions
void PrintMyself (void );
}
void Country::PrintMyself()
{
for (int i=0;i<10;i++)
//print the entire array :: makes my life so easy with
indexing
}
void somefunc(Country& ex)
{
Name usa_country;
usa_country =ex.list[0]; //indexing is no good here - I wish I had
the alias for list[0] as usa
}
Hoping to get the answer.
Thank you.
KK


Well you've not really succinctly defined the problem. You could just
do
#define usa ex.list[0]

but I suspect that's not what you're after.

If you sant to map the string "usa" into one of your Name classes,
how about a std::map?

map<string, Name> list;
list["usa"] = //...
list["uk"] = /...

Name usa_country = list["usa"];
Nov 22 '05 #2
KK <ke*******@yahoo.com> wrote:
Hi,
How can I create alias for a class object? Please go thru this
program to understand the motivation.

Class Name;
Class Country{
Name list[10];
/*My intension is to have:
list[0] - usa
list[1] - uk
list[2] - ..
*/
//define other essential member functions
void PrintMyself (void );
} [snip] void somefunc(Country& ex)
{
Name usa_country;
usa_country =ex.list[0]; //indexing is no good here - I wish I had
the alias for list[0] as usa
}


The way you have it, list is private, and somefunc() has not been
declared as a friend.

--
Marcus Kwok
Nov 22 '05 #3

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

Similar topics

15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
7
by: Lance | last post by:
Is there any way to create an import alias that applies to the entire project? For example, lets say that I want "VB" to represent Microsoft.VisualBasic throughout my entire project. Is there...
2
by: Try Guy | last post by:
I'm not sure if I really understand this whole ownderdraw thing... i want to create my own Windows Forms control (NOT USERCONTROL)...is it ownerdrawing I should start learning or something else?...
2
by: FB's .NET Dev PC | last post by:
I am writing two services in VB.NET, one of which needs to send text strings to the other. After reading, I decided (perhaps incorrectly) that named pipes would be the best interprocess...
2
by: Tarren | last post by:
Hi: I am not sure what the code would be to achieve this. I am looking for a way to give an alias to an object, so I can assign values to the object regardless of the name. What is the way...
4
by: Sean McIlroy | last post by:
hi all is there a way to do this ... class clown: def __init__(self): self.x = 0 self.y = ALIAS(self.x) ## FEASIBLE ? .... so that you get results like this ...
32
by: Joe | last post by:
I am just starting to use Object Oriented PHP coding, and I am seeing quite often the following (this example taken from a wiki): $wakka =& new Wakka($wakkaConfig); What exactly is the =&, and...
2
by: Lee Harr | last post by:
I thought of several ways to add another name for a method in a subclass ... #alias.py class Foo(object): def nod(self): print "nodding" class Bar(Foo):
4
by: WT | last post by:
Hello, Here is my pb: I have a group of classes in 2 namespaces which are exactly simlilar. Theses classes are generated by Visual Studio when inserting a Web Reference, having 2 versions of a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.