Reputation: 2 Apprentice
- New Members
- Active Posts:
- 9 (0.01 per day)
- 29-March 11
- Profile Views:
- Last Active:
- May 25 2012 11:18 AM
- Dream Kudos:
Posts I've Made
Posted 22 Apr 2012for C++98/03, you should pass it a constant reference and then copy that reference into the queue(using copy constructor preferably).
void enqueue(const T& value);
without proper care, C++ can be a bit copy happy. as a general rule, for things like these use a constant reference. that way an extra copy is only made if the user creates a creates a copy.
This is what I had decided on after thinking about it and debugging to see what was going on. Thanks for the detailed answer.
Posted 21 Apr 2012this literally has, *no* purpose. vectors, and many other things in C++, provide iterators. iterators allow for generic code to be written that works for vectors, lists, deques, maps, sets, complex classes like LLVM's module class(has like 4 different types of iterators), and an unbounded number of other data structures. you would be *FAR* better off just using the '=' operator of an std::vector *if* you absolutely needed a copy.
I'm not sure what you mean by this. Are you saying that I shouldn't be trying to convert a templated vector object to a corresponding array? Or are you saying that there is a better way to do this. The code you gave simply assigned one vector to another.
Quoteyou can actually pretty easily convert your sorting algorithm to use iterators.
Yes, I am aware of this and probably will sometime in the future. This was a quick fix to compare output results.
Posted 21 Apr 2012Do you have the function definition in the header file or in a c++ file? For templated functions the definition needs to be in the header file.
Sure enough this was the problem. Thanks for the tip. Any insight as to why this is so with templated functions? Makes me tempted to put all the definitions in the header and just include that to be consistent.
- Member Title:
- New D.I.C Head
- Age Unknown
- Birthday Unknown
CoryG89 hasn't added any friends yet.