When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
128 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
I'm not entirely sure, however...
generally with something like this the approach would probably be to return an iterator
then you can check if iter == q.end(); to see if it's valid
or, alternatively, maybe throw an exception if you try to pop something from an empty queue, because that would be not dissimilar from accessing an out of bounds array index
well, what do you need to delete why? what is the function going to return if the thing was deleted?
I’m just trying to understand memory management and leaks. I believe if I don’t delete it my program will have a leak?
well, if the thing was created via new, you generally will need to delete it yes
Oh, but in this case it’s both
Not*
So I won’t have any leakage
Leaks*
Is that correct?
it's pretty simple: do you delete everything that you new?
Well I just started cpp, so naturally I want to say yes.
In Java garbage collector does it automatically
well, C++ is based on the idea of simply not producing any garbage in the first place
then there's also no need to have someone come pick it up 😉
well, where do you new these things and where do you delete them?
Like in general? i would new when i want to create a new instance of an object? such as Node* temp = new Node(params); then delete after it has been used/outputed to watever needs it?
thats the only case? for example in my Node* temp = qFront; i dont need to delete the temp?
man, this sounds dumb but this is what my professor said.
a node?
a pointer to a node it would seem
i'm assuming that node it points to was created via new
so what's temp then?
temp is just a copy of qFront that stores the data to be deleted so that i can re arrange the pointers
yes
and then you delete temp
yes
so you delete the node that you created via new
Correct.
well
then if we assume you always take everything out of the queue, there should be nothing left that wasn't deleted
ofc you still have the problem that your dequeue function doesn't return anything
right.
well, what should it return?
Well, if im following you correctly. since there wont be anything in the queue it should return null since there wont be anything there?
i'm not following i'm afraid
based on the screenshot, i would have assumed that it should return a CustomerData
what's that type?
CustomerData?
yes
so. maybe i need to extract that data from the node instead?
the node holds CustomerData data
yeah that sounds like a good idea
random note: one really shouldn't use NULL in C++
use nullptr instead
NULL is a C thing. it exists in C++ solely for the purpose of backwards compatibility with C.
there are various issues with NULL in C++
it's bad practise to use NULL in C++
good to know. i can fix that no prob
use nullptr instead
.
i see so the fact that nullptr and Null have different symbols doesnt mean one is c and the other is c++? lol as like a shortcut to know which is right
no
it means one is a kind of value and the other one is a type
or smth like that
tbh, not sure what the symbols there stand for exactly. would have to consult the documentation of your ide for that
(yet)
indeed, I wouldn't doubt it may be forthcoming in newer C language standards, but I don't pay any real attention to C, nor C language standards, either historical or forthcoming
iirc, C23 will introduce nullptr
TIL
not that it matters because who writes C anyways amirite 😛
insert <CHEEKY_QUIP_ABOUT_C_BEING_ABSOLUTE_GARBAGE>
I mean, it arguably gave us C++, so it's not 100% bad, only like 99.9999% bad
do you think im getting this now for not using New or is this a issue with something else
no, you're getting this because you don't have a main function in your program
well, you're getting those because those functions haven't been defined
omg i just realized its a different function as well from what i was working on originally.
no worries
linker errors specifically are something most people struggle with at the beginning
dawg i dont understand its properly defined at the top. how could something be undefined if i can see it in the file properly written out and declared.
I mean, how good is your imagination
short answer: lots of ways
i didnt even write the implementation though. i was given the files to edit LOL
this part of the code https://stackoverflow.com/help/minimal-reproducible-example
in other words: the relevant parts, but all the relevant parts, but only the relevant parts
indeed most of us probably don't want to sit and read 600 lines of test harness if that doesn't relate to the actual core functionality
which file where? are you compiling that file?
i mean if im getting a undefined reference im assuming its just my headers?
no
undefined reference means the function is used in your program but not defined anywhere
Yes, i am compiling my file
time to learn what a TU is
and probably, related, what it means to create and use your own libraries, both shared and static
does your project consist of only a single file?
No, so i have a Queue.h and a Queue.cpp with the implementations additionally im using Queue.h in a tester just to test the functions.
and how are you compiling your program?
if you have, for example, main.cpp, foo.cpp, and bar.cpp then you need to compile all of them
^
in your context, presumably you want to compile all of them into a single result
yea i know. one second im trying to re do it
dont know maybe the VM was running really slow or something but its working now...
this is how i was compiling i just reset VSC and it ran lol
Thanks for ur help dot 🙂 im sure ill have more questions in a bit but thanks for now 
!solved
Thank you and let us know if you have any more questions!
[SOLVED] What is the best Approach to deleting data here?
@thorny grail
This question thread is being automatically marked as solved.