I’m just writing a program which uses the queue stl type.
Queue<packet* queue_;
Queue<packet& queue_;
These two writings are very similar, except that one is pointer and
one is reference.
Is there anything I must be careful when I am using either one of
them?
More specifically, is there anything really different between these
two “queue”s? 7 2023
On 2008-07-13 10:56, thomas wrote:
I’m just writing a program which uses the queue stl type.
Queue<packet* queue_;
Queue<packet& queue_;
These two writings are very similar, except that one is pointer and
one is reference.
Is there anything I must be careful when I am using either one of
them?
Yes, only one of them is legal, you can not have a queue of references,
you can either have a queue of pointers to packets or you can have a
queue of packets, but not a queue of references to packets.
--
Erik Wikström
On Jul 13, 5:44*pm, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2008-07-13 10:56, thomas wrote:
I’m just writing a program which uses the queue stl type.
Queue<packet**q ueue_;
Queue<packet&*q ueue_;
These two writings are very similar, except that one is pointer and
one is reference.
Is there anything I must be careful when I am using either one of
them?
Yes, only one of them is legal, you can not have a queue of references,
you can either have a queue of pointers to packets or you can have a
queue of packets, but not a queue of references to packets.
--
Erik Wikström
why not? References just mean another name for these packet object.
It's correct in my understanding.
Any more details to clarify this?
On 2008-07-13 11:54, thomas wrote:
On Jul 13, 5:44 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
>On 2008-07-13 10:56, thomas wrote:
I’m just writing a program which uses the queue stl type.
Queue<packet* queue_;
Queue<packet& queue_;
These two writings are very similar, except that one is pointer and
one is reference.
Is there anything I must be careful when I am using either one of
them?
Yes, only one of them is legal, you can not have a queue of references, you can either have a queue of pointers to packets or you can have a queue of packets, but not a queue of references to packets.
Please do not quota signatures.
why not? References just mean another name for these packet object.
Since references are just another name for the object it is not an
object in its own right (it does not occupy any memory and does not have
an address*), which means you can not store it in a container.
* At least not according to the C++ standard.
--
Erik Wikström
"Erik Wikström" <Er***********@ telia.comskrev i en meddelelse
news:x2******** ******@newsb.te lia.net...
On 2008-07-13 11:54, thomas wrote:
>On Jul 13, 5:44 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
>>On 2008-07-13 10:56, thomas wrote:
I'm just writing a program which uses the queue stl type.
Queue<packet * queue_;
Queue<packet & queue_;
These two writings are very similar, except that one is pointer and one is reference.
Is there anything I must be careful when I am using either one of them?
Yes, only one of them is legal, you can not have a queue of references, you can either have a queue of pointers to packets or you can have a queue of packets, but not a queue of references to packets.
Please do not quota signatures.
>why not? References just mean another name for these packet object.
Since references are just another name for the object it is not an
object in its own right (it does not occupy any memory and does not have
an address*), which means you can not store it in a container.
* At least not according to the C++ standard.
Is a reference not basically just a const pointer?
On 2008-07-13 18:48, rufus wrote:
"Erik Wikstré—£" <Er***********@ telia.comskrev i en meddelelse
news:x2******** ******@newsb.te lia.net...
>On 2008-07-13 11:54, thomas wrote:
>>On Jul 13, 5:44 pm, Erik Wikstré—£ <Erik-wikst...@telia. comwrote: On 2008-07-13 10:56, thomas wrote:
I'm just writing a program which uses the queue stl type.
Queue<packe t* queue_;
Queue<packe t& queue_;
These two writings are very similar, except that one is pointer and one is reference.
Is there anything I must be careful when I am using either one of them?
Yes, only one of them is legal, you can not have a queue of references, you can either have a queue of pointers to packets or you can have a queue of packets, but not a queue of references to packets.
Please do not quota signatures.
>>why not? References just mean another name for these packet object.
Since references are just another name for the object it is not an object in its own right (it does not occupy any memory and does not have an address*), which means you can not store it in a container.
* At least not according to the C++ standard.
Is a reference not basically just a const pointer?
That might be how the compiler vendors implements it (at least in some
cases) but there are a number of semantic differences between references
and const pointers. As an example a pointer can be a null-pointer while
a reference always refers to a valid object, a const reference can bind
to a temporary, a pointer can not.
--
Erik Wikström
On Jul 13, 11:44 am, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2008-07-13 10:56, thomas wrote:
I’m just writing a program which uses the queue stl type.
Queue<packet* queue_;
Queue<packet& queue_;
These two writings are very similar, except that one is
pointer and one is reference.
Is there anything I must be careful when I am using either
one of them?
Yes, only one of them is legal,
Actually, neither of them are legal. There isn't any class
Queue in the standard. Of course, if he really means
std::queue, then your comments are correct. (But of course, if
he really means std::queue, that's what he should write.)
--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Jul 13, 7:27 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
On 2008-07-13 18:48, rufus wrote:
"Erik Wikström" <Erik-wikst...@telia. comskrev i en meddelelse
news:x2******** ******@newsb.te lia.net...
On 2008-07-13 11:54, thomas wrote: On Jul 13, 5:44 pm, Erik Wikström <Erik-wikst...@telia. comwrote: On 2008-07-13 10:56, thomas wrote:
>I'm just writing a program which uses the queue stl type.
>Queue<packet * queue_;
>Queue<packet & queue_;
>These two writings are very similar, except that one is pointer and one is reference.
>Is there anything I must be careful when I am using either one of them?
>>Yes, only one of them is legal, you can not have a queue of references, you can either have a queue of pointers to packets or you can have a queue of packets, but not a queue of references to packets.
>why not? References just mean another name for these packet object.
Since references are just another name for the object it is
not an object in its own right (it does not occupy any
memory and does not have an address*), which means you can
not store it in a container.
* At least not according to the C++ standard.
Is a reference not basically just a const pointer?
That might be how the compiler vendors implements it (at least
in some cases) but there are a number of semantic differences
between references and const pointers. As an example a pointer
can be a null-pointer while a reference always refers to a
valid object, a const reference can bind to a temporary, a
pointer can not.
The critical point, of course, is that references are not
objects, and a standard container can only contain objects. Or,
the fact that references do not meet the requirements Assignable
and CopyConstructab le. Take your pick.
--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: BCC |
last post by:
Can someone please explain this to me... if I have:
int x = 10;
I can do:
int* p_x = &x;
Compiles okay.
If I have a function though:
|
by: Asfand Yar Qazi |
last post by:
Hi,
Could anyone explain to me why this works? I can't figure out
the wonky const syntax!
class Surface
{
...
protected:
|
by: Tobias |
last post by:
Hi!
I have a problem which is quite tricky.
I need to pass a struct from .NET to a native Win32 DLL.
But i just need to pass the pointer to a reference of that struct.
With my first struct this worked pretty well, accepting to write
unsafe code ;-)
But my next struct has an array inside and I don't get it passed over
to the DLL correctly.
Here my struct in c#:
|
by: Workgroups |
last post by:
I need some clarification with the whole "no pointers in VB.NET" thing,
because it seems like there are "quazi-pointers" happening but I want to
make sure I'm interpreting all this correctly.
Here's a generic class declaration for the sake of example:
Public clsClass
'properties, methods
End Class
|
by: Marcelo |
last post by:
Hi everybody,
I don't understand why I am having a problem in this code.
The problem is that my pointer *phist in main method, it is declared.
Then I send the pointer to my method, and this method creates a new object (a
Matrix) for it.
I suppose that after the new operator, my pointer is pointing to an object, so
when the method has finished, the very first pointer is still poitint to the
created method; however this is not working,...
| |
by: wizwx |
last post by:
Is there anything wrong with the following code?
class A { ... };
class B : public A { ... }; // definitions of class A and B, these are
OK
Foo() {
A & a = B(); // ??
A * p = &B(); // ??
.......
}
|
by: kasthurirangan.balaji |
last post by:
Hi,
Recently i came across a functiion declaration as below
void f(char *&a);
Nowhere i have come across this style. I understand, passing by
reference is always better(to avoid copying), that too added with
const like
|
by: ankitamca85 |
last post by:
difference between reference and reference type?with example
|
by: Natasha26 |
last post by:
I came across some strange declarations and am trying to get the hang of it. Any comments on how to read and use such decl. will be most welcomed.
1) Not sure if i understand this one. It could be that function f can be used to increment the address of a pointer. So to use f(...) give it an argument of type: int*
void f(int*& i) { i++; }
2) I got this one from pg35 of "C++ in a nutshell," i've put arrows to indicate where i got...
|
by: Deanna |
last post by:
I'm writing a C++ managed .dll that I will call from my C# app. The C+
+ code will need to return an object pointer to the C# that will need
to be passed back for subsequent method calls. The C# code doesn't
need to do anything with the pointer, just accept it as a return value
from the first method and then pass it to the rest.
Can anyone get me started here? I can't figure out how to type the
parameter in the C# dllimport statment...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |