Can I have a struct reference (i.e. a reference to a struct)?. I tried
it and it compiles, but are there any gotchas I need to be aware of ? 4 1570
In article <P6********************@bt.com>, Bit byte <fl**@flop.com>
wrote: Can I have a struct reference (i.e. a reference to a struct)?. I tried it and it compiles, but are there any gotchas I need to be aware of ?
Yes and no. You can think of a struct as a class with different access
restrictions.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
* Bit byte: Can I have a struct reference (i.e. a reference to a struct)?
Yes, in the sense that you can have a reference to a struct /instance/,
which we usually just call an 'object'.
I tried it and it compiles, but are there any gotchas I need to be aware of ?
Here are some:
* Aliasing:
That two references refer to the same object, when that is not
expected. Changes via one can then affect what you see via the
other.
* Dangling reference:
A reference kept around after the object it refers to, is
destroyed.
* Assignment prevention:
Having a reference (or a const pointer, or any const member) /in/
an object prevents assignment.
--
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?
Alf P. Steinbach wrote: * Bit byte:
Can I have a struct reference (i.e. a reference to a struct)?
Yes, in the sense that you can have a reference to a struct /instance/, which we usually just call an 'object'.
I tried it and it compiles, but are there any gotchas I need to be aware of ?
Here are some:
* Aliasing: That two references refer to the same object, when that is not expected. Changes via one can then affect what you see via the other.
* Dangling reference: A reference kept around after the object it refers to, is destroyed.
* Assignment prevention: Having a reference (or a const pointer, or any const member) /in/ an object prevents assignment.
Wow, I did not know about the last one (Assignment prevention) - must
read that one up. Any references will be appreciated (I will ofcourse do
the usual Google searches)
>> * Bit byte: Can I have a struct reference (i.e. a reference to a struct)?
Alf P. Steinbach wrote: Yes, in the sense that you can have a reference to a struct /instance/, which we usually just call an 'object'.
I tried it and it compiles, but are there any gotchas I need to be aware of ?
Here are some:
* Aliasing: That two references refer to the same object, when that is not expected. Changes via one can then affect what you see via the other.
* Dangling reference: A reference kept around after the object it refers to, is destroyed.
* Assignment prevention: Having a reference (or a const pointer, or any const member) /in/ an object prevents assignment.
Yes, though keep in mind that these issues (at least the first two) are
present with any use of references, not just references to structs.
Bit byte <fl**@flop.com> wrote: Wow, I did not know about the last one (Assignment prevention) - must read that one up. Any references will be appreciated (I will ofcourse do the usual Google searches)
When a reference is created, it must be bound (at that time) to what it
refers to. The reference cannot be "reseated". So, if you were to try
to assign to a struct with a reference member, then in effect it would
try to reseat the reference. This is not allowed. However, don't
confuse this situation with the situation of copy-construction, which
can have a similar syntax but the above doesn't apply, since we are
creating a new object, instead of assigning a new value to an existing
object.
--
Marcus Kwok This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: phoenix |
last post by:
Hello,
I've got a design question. I need to keep track of some variables and I am
planning to put them inside a class or struct. Basically I'm talking about
10 bools, 20 ints and 2 arrays of...
|
by: thomson |
last post by:
Hi all,
Would you please explain me where will be the heap stored if it
is declared inside the Class, As class is a reference type, so it gets
stored on the heap, but struct is a value...
|
by: Gerrit |
last post by:
Hello,
Is it possible to sort an array with a struct in it?
example:
I have a struct:
public struct mp3file
{
public int tracknr;
|
by: Mike |
last post by:
Consider the following code:
"""
struct person {
char *name;
int age;
};
typedef struct person* StructType;
|
by: Kenneth Siewers Møller |
last post by:
Hi there
I know this probably have been addressed before, but I have an object that
should contain the following
Guid id
String fName
String lName
Could I use a struct for that? I have read...
|
by: JohnGoogle |
last post by:
Hi,
Newbie question...
After a recent article in VSJ I had a go at implementing a Fraction
class to aid my understanding of operator overloading. After a previous
message someone suggested...
|
by: abhiM |
last post by:
I have a struct that has an array in it. I need to assign space to the
array in a function and pass the corresponding struct by reference to
another function so that it can store values into the...
|
by: Zytan |
last post by:
This returns the following error:
"Cannot modify the return value of
'System.Collections.Generic.List<MyStruct>.this' because it is
not a variable"
and I have no idea why! Do lists return copies...
|
by: karthikbalaguru |
last post by:
Hi,
struct sky {
int stars;
struct ocean *oceanptr;
};
struct ocean {
int waves;
struct sky *skyptr;
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
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
| |