|
Is your log class flushing the stream? If you're watching the log file in realtime, waiting for the lines to show up, they might just be buffered (which would happen too in your stubbed test case, except the program ends right after the last call which flushes all the buffers).
|
# ¿ Feb 23, 2008 06:03 |
|
|
# ¿ May 4, 2024 05:34 |
|
Avenging Dentist posted:This is less a question and more a comment, but I discovered the following "feature" in typedefs today (don't ask how): Why the hell would it compile? x is a sub::bar, which is the same as a base::foo, so it doesn't have a b member. Only sub::foo, which is a completely unrelated struct, has a b member.
|
# ¿ Feb 28, 2008 06:26 |
|
Avenging Dentist posted:Well yes, that's the point. The example is greatly simplified; the original involved a complicated chain of template instantiations and was non-obvious, especially since it broke in a completely separate area (the typedef'd template was instantiated with base::foo and all subsequent references to that template, typedef'd or not, used that instantiation). Oh, I thought the "argh" was "argh C++ is so stupid why won't it let me do this" and not "argh I am so stupid how did I gently caress this up".
|
# ¿ Feb 28, 2008 08:38 |
|
Peanutmonger posted:Simple makefile?! Maybe at first, but if you were really into it, you'd go all out and use autotools. Vim (especially with ctags/etc) and autotools make a fantastic development environment. You're insane. Autotools are ridiculously terrible to work with.
|
# ¿ Mar 1, 2008 06:05 |
|
Peanutmonger posted:I probably am. I also probably haven't used autotools well enough to get out of the "honeymoon" phase of how wonderful it is that configure will discover everything for me and build a Makefile with all of the targets I've come to expect. I really enjoyed doing a "make dist" and copying that to my other desktop and building it. Using stuff that's already written to use autotools is great, yeah. Setting up your project to use autotools is a huge, huge pain in the rear end. I like SCons myself, though I haven't used at enough to find the inevitable flaws.
|
# ¿ Mar 1, 2008 21:22 |
|
WalletBeef posted:What is the best, free, windows C++ compiler? As far as I know, your choices are basically Visual Studio Express or MinGW. Express has the advantage that it's closer to the full, for-pay version of Visual Studio, which is what all Windows software ever is built with, but the disadvantage that it's missing some things and lots of documentation or other software you might want to work with assumes you have those things. MinGW is the Windows port of gcc, the compiler used on every OS except Windows, which is completely free itself, so documentation about gcc will usually transfer right over.
|
# ¿ Mar 5, 2008 16:15 |
|
ColdPie posted:I have a question about inheritance in C++. The C++ FAQ says that inheritance is not for code re-use, but rather for polymorphism and other related features. This seems to conflict with the old "Shape" example (class Shape contains a Position method and related variables, Circle and Rectangle inherit from Shape and inherit this method and data, so more code re-use). Is using inheritance for this reason wrong? If so, why? What am I missing here? The point is that Position and related variables logically belong to all the various subclasses of Shape. If you had a method that happened to be coded very similarly for Circles and Rectangles, but not for Squares, you wouldn't want to add a base class that both Circle and Rectangle inherit from but Square doesn't just to hold this method, because that would make no sense. You also wouldn't put the Circle and Rectangle version in the base class and then have Square override it, because the Circle and Rectangle version doesn't apply to all Shapes so it has no reason being in the base class. (You also wouldn't just duplicate the code in the two classes - make a standalone friend function that's called from both, or something.)
|
# ¿ Mar 5, 2008 16:24 |
|
MEAT TREAT posted:Visuacl C++ 2008 Express Edition Uh, Visual C++ doesn't have a monopoly on nice GUI's. I'm not even sure what you mean by that - a compiler that couldn't be used to compile a GUI is pretty useless.
|
# ¿ Mar 5, 2008 16:25 |
|
GT_Onizuka posted:I have never worked with C++ or autotools, and I'm getting super frustrated. I have no idea how easy/difficult this is, but when I have more time, I want to make it much easier to compile (like, ./configure && make && make install easy). If it's a larger problem than I currently think, I'm more than willing to pay a bit, considering the urgency of this. It's almost that simple already. Install automake and autoconf, then: code:
|
# ¿ Mar 6, 2008 03:52 |
|
Mornacale posted:e: Problem solved. Thanks. Pay no more attention to the C++ n00b behind the curtain. The guy below you already posted, but in general, people, if you solve the problem without they board's help, please post the solution! Other people might be wondering what it was.
|
# ¿ Mar 9, 2008 04:38 |
|
very posted:Edit: Actually maybe I have no idea what is going on. Is "this" as it shows up in the debugger supposed to change? Is it showing me the address of this, or something else? I went back to my old implementation and this never changes in any function. While in a method of an object, "this" is supposed to point to the instance that's currently executing the method. If it's pointing to invalid memory, something is very, very wrong. (If you're not in an object method, it'll just be undefined.) It's expected to change as soon as you enter a new object. For example, in the following code if you step into each function call, it'll change as you enter the functions and be restored when you come back out. If you're not entering another function, it shouldn't change. code:
The most common reason for "this" to be invalid is if you call a method using a bad pointer, but this would only give you one single invalid value (and it usually crashes pretty quickly). If it keeps changing to a bunch of different bad values, something very weird is going on. code:
|
# ¿ Mar 13, 2008 04:21 |
|
schnarf posted:I've got a class inheritance question. I'm writing a scheduler using templates, so that I'll have a generic framework for the scheduler, and the actual process function is virtual so that I can write a variety of schedulers for whatever datatype and scheduling algorithm I want. This is for an assigment. My question is, the schedulers that I implement, inheriting from my base class Scheduler<T> will not need to be templated; they'll use only one datatype because the algorithm will be specific to that datatype. How do I specify that the inherited class isn't templated, but rather uses a specific datatype? Were you required to use both templates and inheritance in this assignment? Because it seems way more complicated than it's worth. "Schedular<T>" is not a class. It's a family of classes, "Schedular<int>", "Schedular<string>", "Schedular<SomeOtherClass>", etc. So you have to pick just one individual class (ie. just one instantiation of the template) to inherit from: code:
One way to get around that is code:
In summary, rethink this. You probably need generics OR inheritance, not both.
|
# ¿ Mar 18, 2008 06:25 |
|
A char is not an object.
|
# ¿ Mar 19, 2008 15:06 |
|
BraggPxnk posted:drat, I was hoping there would be something a little easier than learning an API but oh well. I'm a big fan of Python + Qt, although if one of the goals of this is to improve your C++ programming skills, just plain C++ and Qt would be more appropriate.
|
# ¿ Mar 25, 2008 06:19 |
|
ColdPie posted:What would you suggest? It includes common utilities, constants, and structs that are used in a whole bunch of sources. What's the alternative? I'm seriously asking here, I would love to avoid that mess in future projects. Is the mess causing any concrete problems? Makefiles slow due to dependency analysis, etc? If not, don't bother trying to avoid it - the compiler's perfectly capable of dealing with crap like that. It's not 1989 anymore.
|
# ¿ Mar 27, 2008 05:37 |
|
ColdPie posted:Absolutely not, it works fine. It just feels messy and "bad designy" like he mentioned. If it's normal, all right, just doesn't seem like the best way to do things. Well, one thing is that you're doing a global dependency track. That's always going to be both messy and useless. Look at each individual C++ file and you'll see something that looks a lot more like a plain tree for each (until they join together at that one file that's included by everyone). In fact, even for the global imposing some order on that graph will help a lot. It looks like it was drawn with graphviz behind the scenes - graphviz's default format always leads to messy looking graphs. If you assigned ranks to the nodes so that all .cpp files were at the bottom and the layout favoured vertical rather than horizontal arrangements you'd get a much more pleasing lattice.
|
# ¿ Mar 27, 2008 05:53 |
|
Sarah Sherman posted:Holy poo poo, after looking over this code I understand (vaguely) what is happening and what is going on in each section of the code, but I definitely do not have the programming skill to actually write a program like this. Thanks a lot for the help and discussion guys, but it looks like I'm going to have to scrap this project until I know more. Once I think I have the skills to actually write this program, then I'll for sure speak up again if I need some help. This thread is a great resource, and I enjoy keeping up with this thread (and this subforum in general). If you're just doing this for yourself, and not a school project, try Python. The major structure of the program will be the same, but you won't have to spend so much time worrying about C syntax and arcane function naming.
|
# ¿ Mar 31, 2008 23:37 |
|
TurtleBoy posted:I am looking into programming a game and I had a question which google is proving useless to answer, possibly because I am asking it the wrong questions. Point out to the artists that no matter how much work you spend hiding the art, people will still be able to take screenshots of it.
|
# ¿ Apr 1, 2008 18:50 |
|
Captain Frigate posted:Can anyone see anything wrong with these function declarations? I keep getting "previous declaration of 'readFlights' was here" and "previous declaration of 'print_flight' was here" when I try and compile it. It means you're including declarations of those functions more than once, and the different declarations don't match. The most obvious way is if you accidentally have an older version in a different header file or something. I see you use a lot of custom types (airport, route, etc.) so, assuming that's in a header file, it could be you're including the header file twice and redefining one of those types in between.
|
# ¿ Apr 7, 2008 04:27 |
|
Does your header include #ifndef guards?
|
# ¿ Apr 7, 2008 04:42 |
|
Captain Frigate posted:No. Could that be what is causing the problem? No, I was just wondering.
|
# ¿ Apr 7, 2008 04:46 |
|
Captain Frigate posted:I had no idea what that was before you brought it up and I searched for it. Some people don't already know a language back and forth. The point is, why would I have asked (not to mention I'm the second person to bring it up) if it wouldn't be causing the problem?
|
# ¿ Apr 7, 2008 05:04 |
|
Try boost::enable_if
|
# ¿ Apr 11, 2008 19:57 |
|
lhunc posted:Another C newb question, this time regarding the passing of structures to functions. As a general principle, you're probably better off splitting this into a declaration of a struct type, and a declaration of an array of that type. code:
quote:and then a function which takes an array of note structures, which I'm sure is wrong... This is one of the areas where C and C++ differ. In C, it's code:
Since this is really annoying, generally you take that structure and typedef it to an easier name. code:
code:
code:
|
# ¿ Apr 14, 2008 22:31 |
|
Did you declare that struct in a header file? Are you sure you're not including an older version of the header or something?
|
# ¿ Apr 14, 2008 22:40 |
|
MEAT TREAT posted:Thanks for the tips Plastic Jesus. The reason that loop is so weird is because I'm supposed to give a 0 when they guess the right color but it's not in the correct position and a 1 when it's the right color and the right position. The best thing to do is have a message the server sends the client to tell it that it's being shut down, and preallocate all memory needed to send that message at the beginning of the program. Then if calloc ever returns null you can send that last message before shutting down without having to allocate more memory. It's not that terrible to shut down and leave the client hanging, though, since the client should be able to deal with timeouts anyway (what happens if the network goes down?) - better than trying to forge ahead without memory.
|
# ¿ Apr 21, 2008 19:38 |
|
Just pretend they're 7 digits wide instead of 8. So instead of 0,8,16,24, the sequence is 0,7,14,21 0 * 2^24 + 0 * 2^16 + 2 * 2^8 + 1 * 2^0 = 513 (wrong) 0 * 2^21 + 0 * 2^14 + 2 * 2^7 + 1 * 2^0 = 257 (right)
|
# ¿ Apr 24, 2008 00:38 |
|
Yeah, but I didn't even notice the 2 made no sense, so I fail at computer science. I assume it was supposed to be "00000010 00000001"
|
# ¿ Apr 24, 2008 06:48 |
|
If you're trying to save it to a file to print, I don't understand why you're even trying to display it on the screen. Use an imaging library, not a GUI one. (I don't know enough about them to know which can handle really large images well, though.)
|
# ¿ Apr 28, 2008 04:50 |
|
Scaevolus posted:Look up line-drawing algorithms. You could initialize a 12GB raw image file with zeros, then draw lines by doing file seeks and writes. It wouldn't be pretty, and it might take a very long time, but with good filesystem caching it might be manageable. That's the worst idea I've ever heard. The man is doing VECTOR GRAPHICS.
|
# ¿ Apr 29, 2008 04:58 |
|
That's definitely better than "i < 10000000" because it's checking against an actual time instead of just an arbitrary counter, so it works the same no matter how fast your processor's running. The counter method is completely broken; this is just unoptimal. What you want is "sleep" (I think it might be _sleep in Visual C++, nut that shouldn't matter to you). Problem is it only takes whole seconds, so the lowest you can do is "sleep(1);" to sleep for 1 second. If that's ok, this is the easiest. If that's not good enough, you can use "nanosleep" (which I think is Unix-only), which takes a duration measured in nanoseconds but it's a bit more complicated because you need to fill in a structure instead of just passing an int. Google should be able to tell you how to use it.
|
# ¿ Apr 30, 2008 21:35 |
|
Avenging Dentist posted:There's also usleep, which takes microseconds. All of these should be in unistd.h usleep isn't available everywhere, though - nanosleep and sleep are the most portable. Probably doesn't matter in this case, but it's a good idea to get in the habit of using nanosleep.
|
# ¿ Apr 30, 2008 22:10 |
|
Recursion-wise that looks right - the only problem is "4(x)" won't compile, it's "4*x".ColdPie posted:Just kind of at a first glance (about to run out the door to school myself), this looks all right. I'd add in a check to make sure x isn't negative -- that'd create an infinite loop. Depending on exactly how the requirements are worded, I'd throw the check for <=0 at the start: This is always a good idea, and falls under "always check for unexpected inputs". The function will never get down to a negative number while it's recursing, but it'll break if someone else calls "recurse(-1)". The easiest and best fix is to change it to "unsigned int recurse(unsigned int x)" so it's not even possible to pass it a negative number.
|
# ¿ May 5, 2008 16:16 |
|
Since this is C++ code, why doesn't LongPacket just inherit from Packet so you can use static_cast?
|
# ¿ May 5, 2008 22:35 |
|
Paniolo posted:Also you can't declare an array like this: Actually you can in gcc - it's a compiler extension. (You shouldn't, though, because it makes your code non-portable.)
|
# ¿ May 6, 2008 15:57 |
|
Smackbilly posted:This may be silly/stupid, but is it in any way possible to do this? Off the top of my head, try code:
|
# ¿ May 6, 2008 21:18 |
|
Professor Science posted:What the gently caress, Qt 4.4 supports futures? Holy poo poo. I took a look for that and couldn't find any docs. Can you point me to a reference?
|
# ¿ May 8, 2008 04:17 |
|
Oh, I completely missed that 4.4 already had an entry on the main doc page - I was looking around for previews and getting pissed off that all the Google links were outdated. Wow, the whole QConcurrent framework looks fantastic.
|
# ¿ May 8, 2008 15:29 |
|
Vanadium posted:Or you could just use boost::add_pointer<int>::type foo, bar; to avoid any confusion or ambiguity. I love me some boost, but that's disgusting.
|
# ¿ May 15, 2008 01:46 |
|
|
# ¿ May 4, 2024 05:34 |
|
vanjalolz posted:Ha Ha what the hell? Do Boost pointers actually add anything useful to warrant such terrible syntax? It's meant to be used in contexts where there isn't any other syntax. You're not supposed to use it in standard situations. For instance, in a template function you want to say, "Whatever type the parameter is, get a pointer to that type." code:
|
# ¿ May 15, 2008 06:03 |