473,988 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array of references

hello.
why can't you have an array of references ??? can someone enlighten me on
this ??
thanx.

Jul 23 '05 #1
4 10177
maadhuu wrote:
why can't you have an array of references ??? can someone enlighten me on
this ??


You can only create an array of objects. References are not objects.

V
Jul 23 '05 #2
* maadhuu:
why can't you have an array of references ??? can someone enlighten me on
this ??


It's simpler that way.

A reference cannot be assigned, and has no size.

If arrays of references were allowed they would therefore have to be treated
specially in every way.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #3
maadhuu wrote:
why can't you have an array of references ???


Because references are not "things". They are not objects; you can't point
to them, take their addresses, etc.

Naturally, many situations implement them as invisible pointers. However, if
the C++ Standard allowed any syntax more that forced them to become
"invisible pointers", such law would limit the kinds of optimizations
compilers can subject them to. You can't point to a reference, and index
addressing is explicitely defined as a form of pointing-to.

The next question should be this: What benefit can you expect to derive from
an array of references. If you need to replace -> with ., then look to your
own interface, not to the Standard. Here's pseudo-C++ showing such an
interface:

class Things
{
private:
std::vector<Thi ng *> things;
public:
Thing & operator[] (int idx)
{
Thing * pThing = things[idx];
assert(pThing);
return *pThing;
}
};

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #4
In article
<b8************ *************** ***@localhost.t alkaboutprogram ming.com>,
"maadhuu" <ma************ @yahoo.com> wrote:
hello.
why can't you have an array of references ??? can someone enlighten me on
this ??
thanx.


You might look at std::tr1::tuple if your std::library supplies it, or
at boost::tuple if your std::lib doesn't. It may supply you with the
functionality you're looking for.

#include <tuple>
#include <iostream>

int main()
{
int i, j, k;
std::tr1::tuple <int&, int&, int&> int_refs = std::tr1::tie(i , j, k);
std::tr1::get<0 >(int_refs) = 1;
std::tr1::get<1 >(int_refs) = 2;
std::tr1::get<2 >(int_refs) = 3;
std::cout << i << '\n';
std::cout << j << '\n';
std::cout << k << '\n';
}

1
2
3

-Howard
Jul 23 '05 #5

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

Similar topics

2
2032
by: Kaptain524 | last post by:
Hello, I am using PHP 5.0.4 with Apache 2, on WinXP Pro. This behavior appears to be fundamental however, and should not be affected by platform. It would seem that there is some kind of bug in the process that creates the reference when it is being assigned to an array element within itself. If it is already referenced, it just assigns the existing reference and avoids the problem.
9
2312
by: Timothy Madden | last post by:
Hello If I write a function like this void Process(double Data) { ... } it is ok, but if I try class DataProcess { double (&Data); DataProcess(double Data)
10
10315
by: Fraser Ross | last post by:
I need to know the syntax for writing a reference of an array. I haven't seen it done often. I have a class with a member array and I want a member function to return an reference to it. Returning a pointer to the first element might do but I want to do what I've said. Fraser.
2
5259
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it down to a very simple test case which can be cut-n-pasted into a .html file and viewed in a browser: ============================================================================
104
17158
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from that array Could you show me a little example how to do this? Thanks.
4
71128
by: None | last post by:
Hi, I have declared array as Int ids = new int; In ArrayList we can remove specified index using RemoveAt(5) method. My question is how can we do this one with int array (single dimensional array) or else is there any alternative solution for this? If anybody knows the solution pls let me know.
7
6453
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are now thown out of the array released properly by the CLI?
11
13533
by: rayreeves | last post by:
How do I declare an array of references to the elements of an array of values? Ray
2
360
by: subramanian100in | last post by:
From http://groups.google.com/group/comp.lang.c++/browse_frm/thread/d5da6e5e37fd194d/6e2e8424a1cfbd2b#6e2e8424a1cfbd2b the following portion is taken. "Mike Wahler" <mkwah...@mkwahler.netwrote: " An object will occupy memory space (in your program's memory area). A reference is simply another
31
3298
by: siddhu | last post by:
why can't we have array of references.
0
11912
Oralloy
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...
0
11488
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...
1
11704
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,...
0
10983
tracyyun
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...
0
10152
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...
0
7691
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
6494
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...
0
6657
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3824
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.