|
JoeNotCharles posted:Since we're iterating over actorsToDelete, removing things from actorList doesn't affect the iterator, and then actorList goes out of scope and gets cleaned up. Too bad it's unnecessarily O(n2).
|
# ¿ Jul 27, 2008 21:36 |
|
|
# ¿ Apr 29, 2024 03:32 |
|
TheSleeper posted:Uh, you mean O(2n), no? The absolute max here is that it iterates the entire list twice I'm not seeing where it can loop n2 times. Well okay if you have magical linked list where .remove() is O(1).
|
# ¿ Jul 27, 2008 23:32 |
|
prolecat posted:In that case, you're stuck setting the members of the struct in the body of the class constructor, barring some language feature I'm unaware of. Since structs have a default copy constructor, you can define a function that returns said struct (something like MyStruct MakeDefaultMyStruct()) and initialize the member variable with that.
|
# ¿ Jul 31, 2008 10:20 |
|
Vanadium posted:Doing about anything with that union is an aliasing violation. No it's not; the whole point of unions is to avoid strict-aliasing (not aliasing) violations. You probably mean it's undefined to write to a union member and to read from another one (mostly).
|
# ¿ Aug 26, 2008 11:06 |
|
FearIt posted:I've tried casting windowClassName as an (LPWSTR) but then the code compiles but does nothing. This is the worst way to solve compile errors in C/C++. Your solution isn't that great either. Why not pass in L"MyString" or _T("MyString")? (I forgot the right one to use.) floWenoL fucked around with this message at 04:35 on Sep 13, 2008 |
# ¿ Sep 13, 2008 04:26 |
|
ultra-inquisitor posted:If you're using the STL you may as well use string. std::string doesn't make the same guarantees about memory locations as vector<char> does, I believe.
|
# ¿ Sep 15, 2008 22:40 |
|
Risita posted:If you want your code as short as possible, make an array of size 3 and bubble sort it! Or are you required to use 3 separate variables? quote:It has to be using if statements, as it is in a beginning programming class.
|
# ¿ Sep 20, 2008 03:00 |
|
Avenging Dentist posted:Yeah but right-shifting in C is an arithmetic shift. i.e. 0b1??????? >> 7 = 0b11111111 == -1 Implementation-defined.
|
# ¿ Sep 25, 2008 03:29 |
|
Pooball posted:!!~(-1<<a-b) What the gently caress is this?
|
# ¿ Sep 25, 2008 04:16 |
|
JoeNotCharles posted:If you make this function a pure virtual instead, it will 100% guarantee that the base version will never be called, because it doesn't even exist: That's not true.
|
# ¿ Sep 29, 2008 09:30 |
|
Whilst farting I posted:I need to alphabetize a two dimensional string vector by the first column. An excerpt looks like this Why aren't you using std::set or at least std::sort? Edit: Why does your inner loop do the same thing (readAllItems) as your outer loop? floWenoL fucked around with this message at 23:43 on Oct 10, 2008 |
# ¿ Oct 10, 2008 23:38 |
|
Whilst farting I posted:The dataset is indeed truly immense - it's several thousand lines long. Since when was several thousand lines an "immense" dataset?
|
# ¿ Oct 14, 2008 04:05 |
|
Cross_ posted:%i, as the letter implies, is expecting an int. You are feeding it a char, that leaves printf with taking "random" values from nearby memory to fill in the missing 3 bytes. This is completely wrong.
|
# ¿ Oct 18, 2008 07:20 |
|
Janin posted:All memory allocated by malloc() is free'd when the application exits. If you're using a memory leak checker, explicitly freeing your allocations will prevent false positives. How is it a false positive if a memory leak checker finds your memory leaks? It's also worth pointing out that not all operating systems clean up after programs (but most modern ones do). But the practical reason is that you usually want to be able to use a program continuously without it eating up your memory. Short-lived programs like compilers don't have to worry so much and in fact compilers are notorious for being leaky. floWenoL fucked around with this message at 11:07 on Oct 23, 2008 |
# ¿ Oct 23, 2008 11:03 |
|
chocojosh posted:Thanks AD! I don't understand why you're doing things the way you are, but I'm already certain it's completely wrong. It's also worth pointing out that even if you could cast ClassRecord** to SymbolRecord** the code would still be wrong (you'd be dereferencing an uninitialized pointer).
|
# ¿ Nov 3, 2008 09:41 |
|
Anunnaki posted:cin stops after the first whitespace. I'm entering a whole string of morse code, each character separated by a space. I'm more curious about the "corrupt the I/O buffer" part.
|
# ¿ Nov 24, 2008 03:43 |
|
hexadecimal posted:well what if you don't want to use boost, or can't? its not an awful #define its very useful, at least for me See what happens when either _it or _l is a computed expression (e.g., FOREACH(i++, my_map)). It's a pretty awful macro.
|
# ¿ Nov 24, 2008 05:19 |
|
User0015 posted:If anyone was up for it, I had some questions I'd like to ask via e-mail. That, or start my own thread. I don't think a thread really warrants my questions, since they'd mostly be single question/comment types. If only there were a thread specifically dedicated to (C++) questions not worth their own thread...
|
# ¿ Nov 24, 2008 22:11 |
|
Painless posted:Does anyone know what's going on with std::sort? Is it just that GCC 3.4.4 and visual c++ express suck at optimizing, or am I doing something wrong here? You're comparing apples and oranges; your comparison function (which is wrong, by the way) is not the same as std::greater<int>. I don't know if that's the only factor, but it's the most glaring one.
|
# ¿ Nov 24, 2008 22:13 |
|
Nahrix posted:But I'm using FILE** as a parameter already. the expression "file" is of type FILE** (or decays to it) so adding &file is of type FILE***, and you're trying to pass it to a function which takes FILE**.
|
# ¿ Nov 25, 2008 00:02 |
|
Adhemar posted:What's wrong with a post-increment on an iterator? It creates a temporary needlessly, which may or may not be optimized out.
|
# ¿ Nov 25, 2008 00:47 |
|
hexadecimal posted:i think you can override copy constructor. In your abstract class, there are probably some protected fields, so copy them in AbstractClass copy constructor then in the derived classes call the super constructor and copy the fields that are specific to derived class. This 'solution' is totally broken.
|
# ¿ Nov 25, 2008 02:58 |
|
Avenging Dentist posted:Off the top of my head, the easiest solution would be to use CRTP: I'm pretty sure that won't work, given the earlier discussion about virtual functions from one superclass 'fulfilling' an abstract virtual function from another superclass. I can't think of a way that avoids having to write clone() for each subclass. Edit: Wait, what about code:
code:
floWenoL fucked around with this message at 03:15 on Nov 25, 2008 |
# ¿ Nov 25, 2008 03:05 |
|
hexadecimal posted:How can something like that be possible? hexadecimal posted:check out this #define I have found somewhere and have been using for a while. It makes iterating through STL containers a lot easier. Hmm...
|
# ¿ Dec 4, 2008 09:50 |
|
TSDK posted:I can think of a few options, but none of them are going to get you what you want with zero changes. The simplest and clearest change I can think of doing is to put the handler member into an anonymous union, e.g.: Anonymous unions are C++-only I believe. In C, an empty param list means (or used to mean) the function can take any number of arguments, not that it takes no arguments. There might be a GCC switch to turn that behavior back on.
|
# ¿ Dec 10, 2008 21:55 |
|
Ari posted:Shouldn't he get rid of the thing2 = NULL and replace delete with delete[]? No.
|
# ¿ Dec 11, 2008 06:48 |
|
rawstorm posted:Now I want to free up the memory I just allocated. What do I need to type on the next line that would free up that memory? Nothing because apparently you can't post code that makes sense or compiles.
|
# ¿ Dec 11, 2008 08:53 |
|
ultra-inquisitor posted:edit: it's worth pointing out of course that doing quicksort this way is really an inefficient version of mergesort, one of the strengths of quicksort is that it can be done in-place. I don't understand why you think it's like mergesort. There's no merging that needs to be done as you know one of the lists is sorted and less than the pivot, and the other is sorted and greater than the pivot, and concatenating two lists together is a simple constant-time operation. Edit: In fact, if you're careful to work only with node pointers you can quicksort "in-place" in a different sense, and if T is a large object it might actually be faster than quicksorting an array. floWenoL fucked around with this message at 22:35 on Dec 12, 2008 |
# ¿ Dec 12, 2008 22:23 |
|
Whilst farting I posted:It always just returns every time a list has one element or 0 elements, Isn't that what you want? It's what the top of your code does, anyway. Also, your for loop simply infinite-loops.
|
# ¿ Dec 13, 2008 04:15 |
|
Avenging Dentist posted:I'm not sure what you are attempting to say here, but it is almost certainly wrong. Hexadecimal giving a stupidly wrong answer to a question which someone has already answered? No way!
|
# ¿ Dec 15, 2008 07:07 |
|
Painless posted:I had a weird crash once on Visual C++ calling a function that was something like this: Well that's explained as simply that the "real" dereference in the code Visual C++ generates happens on the "bar += baz" expression, although the behavior is undefined as soon as you dereferenced the null pointer to get the "null reference".
|
# ¿ Dec 15, 2008 20:45 |
|
hexadecimal posted:also most of the time you want to abstain from C++ vector and just use static arrays. Make them as big as the boundary cases, and you'll be good. Are you giving bad advice on purpose, or are you just a horrible programmer? I'm inclined to believe the latter because that is some truly horrible code.
|
# ¿ Dec 24, 2008 00:21 |
|
hexadecimal posted:It's a good advise for UVa problems because you are not trying to use good design here, just what works the fastest to solve particular problem. You allocate arrays with maximum size for some task because it will work for all test cases and you only make it once. You are shooting for speed and easy to program over memory usage. Speed is a bullshit reason, especially if you are talking about vectors vs. static arrays. vectors are definitely easier to work with than static arrays for all but the most trivial tasks. At worst, you can just call .reserve() or .resize() if you want. quote:Using vector is slightly more expensive, and usually you can do all of the same things just with large arrays that you can reuse between problems (don't have to resize vector, or create new one). memset works faster than vectorz. Speed is not a factor if you use vector right. I don't know what vectorz is, but I assume it's some vector-zeroing function you wrote. In any case, you can call memset on &v[0]. quote:Also what is so horrible about it. It was quick to write and passes the test cases. It's horrible enough that you had to clean it up a bit.
|
# ¿ Dec 24, 2008 00:44 |
|
hexadecimal posted:It wasn't bad code and there are no mistakes as well as bad advise. You and floWenoL just nit picked one of my points in order to troll. It was bad, or at least poorly-worded, advice. Believe it or not, I'm more interested in talking about C++ programming, which includes pointing out bad code/practices/advice, than in trolling anyone. Perhaps rather than crying 'troll', you should reflect on why it seems like every one of your programming-related posts has someone criticizing it.
|
# ¿ Dec 24, 2008 01:12 |
|
shodanjr_gr posted:
Hey guys, time for another round of "Guess the problem without the error message"! (My guess: you don't actually define Foo::A_STATIC_MEMBER_OF_FOO anywhere (the code you have just declares it).)
|
# ¿ Dec 31, 2008 01:06 |
|
Avenging Dentist posted:Is your mind blown??? :O
|
# ¿ Dec 31, 2008 03:10 |
|
hexadecimal posted:And all thats needed to print out solution is: cout<<pos[0].first<<" "<<pos[0].second<<endl; Why sort if all you need is the max element?
|
# ¿ Jan 3, 2009 05:01 |
|
hexadecimal posted:Well considering that I got AC on this problem, yes. Arrays? Loops? make_pair? heaps/maps? What are those?? Edit: unsigned long long? wtf? floWenoL fucked around with this message at 05:57 on Jan 4, 2009 |
# ¿ Jan 4, 2009 05:36 |
|
shodanjr_gr posted:Say I have a function: Why don't you just make myFunction() return the pointer?
|
# ¿ Jan 4, 2009 05:39 |
|
|
# ¿ Apr 29, 2024 03:32 |
|
hexadecimal posted:It doesn't change the outcome of the problem, or impact total runtime significantly does it? Also we wouldn't be having this discussion if floWenoL wasn't nitpicking my posts again. God forbid I try to nudge you into becoming a better programmer! Edit: hexadecimal posted:The reason it works without including, I guess, is because compiler knows to look there by default if it can't resolve some things, since it is standard library for the language. This is completely false (and going in hexadecimal.txt). floWenoL fucked around with this message at 08:39 on Jan 4, 2009 |
# ¿ Jan 4, 2009 08:30 |