That isn't exactly how it works... You are assigning it the value of tmp. Thus it is copying the data over.
That isn't exactly how it works... You are assigning it the value of tmp. Thus it is copying the data over.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
@phantomotap
i just got this job and my opinions don't mean anything no matter how correct it is from an objective point of view. i need to prove myself in other ways first.
@Elysia
again, i don't want to be that vocal this early in my job. however, my supervisor is also the team lead and he does a lot of coding as well, so i can't use that argument....because again, it implies he can't do his job.
my girlfriend tells me that i'm getting paid to do as he says...so i should just do it, but the programmer in me always wants to find the best way of doing things.
You wouldn't have been hired if the company and your peers did not value your input.
Just use a smart pointer and document the change. If your boss gets ........ed then you'll just have to explain.
I don't know if you are serious or not, but I almost made it meta-programming style. ^_^Oh and phantomotap, I love your examples. They're always so complex
-_-i just got this job and my opinions don't mean anything
You can't know that until you present your case. If you really are new to the job scene/new to the house they will not fire you for the attempt at simplifying your job and improving your work. If your team really doesn't value your input... you are screwed anyway.
Soma
Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good. Redundancy is always good.
i did. he said don't worry about redundancy and just copy the data over and over again. i had a very strong opinion not to do this and said that if that data is already in memory somewhere else and is not going to change, i should reuse that. he thought that i was making life difficult for myself. i said i can handle it and i believe that it's a good design. i eventually let me use the reference (pointer is still a no-no) and said that it'll be open to review and i may have to change everything if he doesn't like it.
the good news is that my current solution will compile with or without the '&' which means i can turn on/off copying quite easily.
as for C# i'm very adept in that language because that was what i used for 3 years at my previous job. it would actually make a lot of sense to use C# for my application because we're much more concerned with 'safety' than performance....even though when i was hired the manager said they still use C++ because of performance.
i've grown to like C++ again, like RAII, smart pointers, etc. it's all very interesting and cool, although i hate the idea that i'm not allowed to use the language's most powerful features.
Last edited by bling; 09-05-2008 at 10:39 PM.
Well if you just need a const copy of the object that won't get changed externally, then I would make it a regular variable (no reference or pointer). I thought you wanted to make it a reference because you want your copy to see any changes that were made to the object externally?
You need to chat with your boss about the reasons for not using raw pointers. Almost certainly it's because of the possibility of forgetting to delete something and causing a memory leak.
That being the case, using a reference instead does not lessen the possibility of getting a memory leak. Furthurmore you actually just make things somewhere between difficult and impossible to do what you need to do. So don't do this.
Here's something you need to remind your boss. Weak/raw pointers are absolutely necessary. For example, when two classes have a ref-counted smart pointer to each other. Neither can be freed. The solution to such problems is to use a weak/raw pointer in one of them. If you can't do that then his rules are causing the very problem he is trying to prevent - leaking. Seriously you need to give him the circular references counter-example.
What about pointers to things the object doesn't own? Holding smart pointers to such items would be ridiculous as you'd have to explicitly detach from the smart pointer to prevent from deleting something you're not supposed to. However this is the case where references can be the right thing to use, and even then I quite probably wouldn't.
What's more, how are you supposed to implement your own resource handling classes. E.g. to write a smart pointer you must use a smart pointer? Are other resources such as handles not just as important, if not more so, to prevent from being leaked? What's his policy on other types of resources?
I am all for code reviews. We use them heavily where I work. They're a much better way of improving code quality than making arbitrary rules.
Last edited by iMalc; 09-06-2008 at 01:15 AM.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
I'm pretty serious, but I also like when you chime in your examples ^_^
They look nice.
You are aware that if you use a reference, then you CAN'T use the assignment operator because a reference can't be reassigned, right?
Although without it, there's no problems.
I'm just checking to make sure you're aware.
Your in quite a swamp there. Hang on to the branch! Don't let yourself sink!
my first project's design involved a (half) circular reference. a class derived from a threading class that we use, which implemented a run() function. i needed to add a 2nd thread to the same class, so i made an inner class implement the same base thread class, and passed in a pointer of the base class to the inner class. so it was just one way, the inner class held a pointer to the main class so i could access privates.
the smart pointer implementation we use threw a hissy fit about this (because the inner class would try to delete something that still should exist) so i pointed that out to my supervisor, mentioning that i wasn't able to use a smart pointer in this case. (i've mentioned using boost many times but his reply was to keep using their in-bread library). he replied saying isn't using circular references a bad design??
i tried to convince him that it's useful...for instance in the .NET framework u'd have stuff like:
where u can create a hierarchy of information to make it easier to understand. he said i should forget about my C# practices because i'm programming in C++ now. i didn't exactly agree with this statement and probably shoulda used a C++ example....i wasn't sure what to say to that so i just accepted what he said because i felt it was derailing into a battle of egos.Code:class B { int a,b,c; }; class A { B* b; };
Last edited by bling; 09-06-2008 at 01:07 PM.