A way to get past "array of references" error
A way to get past "array of references" error
ok, so I had started coding, and had all these tedious values for making an array of references so that rather than go *reg16[1], I could just go reg16[1] and prevent lots of typos and errors, and also make it look nicer....well, after about 10 minutes of programming it all in, and writing some test code, I go to compile and get a nice clear error: "Error: array of references"
why the crap can I not have an array of references, I can make a frikkin array of const pointers but I can't do it with references? wtf!?
why the crap can I not have an array of references, I can make a frikkin array of const pointers but I can't do it with references? wtf!?
Re: A way to get past "array of references" error
References aren't pointers. A pointer is the actual numerical identity of an element in memory; basically an integer. A reference, on the other hand, is the actual variable, that is, the variable itself is passed by the compiler instead of the value held within.hckr83 wrote:why the crap can I not have an array of references, I can make a frikkin array of const pointers but I can't do it with references? wtf!?
I believe that's what it is, at least, I think I do. (I'm not 100% sure.)
C8H10N4O2 | #446691 | Trust the nodes.
Stop using ancient pointers and use references whenever possible.JamesM wrote:I've got to say the only time I have ever used references is when I'm forced to when doing operator overloading.
Stick to the pointers I say!
If you need some pointers on references, click here
I'm a more User Friendly sort of guy. Maybe I'll add it to me list though. It seems pretty funny.hckr83 wrote:wow...someone else that reads xkcd...(I've done that in real life, btw...lol)
C8H10N4O2 | #446691 | Trust the nodes.
You posted the same xkcd link twice. Did you mean to do that?Candy wrote:Stop using ancient pointers and use references whenever possible.JamesM wrote:I've got to say the only time I have ever used references is when I'm forced to when doing operator overloading.
Stick to the pointers I say!
If you need some pointers on references, click here
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
I wasn't sure the first link would be noticed at all.JamesM wrote:You posted the same xkcd link twice. Did you mean to do that?Candy wrote:Stop using ancient pointers and use references whenever possible.JamesM wrote:I've got to say the only time I have ever used references is when I'm forced to when doing operator overloading.
Stick to the pointers I say!
If you need some pointers on references, click here
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: A way to get past "array of references" error
References are a special kind of pointers made because the normal pointer system is so unsafe. On the other hand, references are too restrictive...Alboin wrote:References aren't pointers. A pointer is the actual numerical identity of an element in memory; basically an integer. A reference, on the other hand, is the actual variable, that is, the variable itself is passed by the compiler instead of the value held within.hckr83 wrote:why the crap can I not have an array of references, I can make a frikkin array of const pointers but I can't do it with references? wtf!?
I believe that's what it is, at least, I think I do. (I'm not 100% sure.)
This can be seen by looking at the generated asm code for these functions:
Code: Select all
int CallByRef(int &ref) {
return ref;
}
int CallByValue(int *ref) {
return *ref;
}