|
Anunnaki posted:Err, I'm sorry, I'm just going by what my IDE calls it; what I mean is whether or not you begin a new line for the opening bracket for any multi-line function, like an if statement, or whatever. Whoknew's code was written with the style where the opening bracket starts on the same line. As long as you consistently use a single sane style, if they seriously care which style it is you probably don't want to work for them.
|
# ¿ Jan 15, 2009 16:16 |
|
|
# ¿ May 3, 2024 02:49 |
|
ultra-inquisitor posted:Obviously I shouldn't be passing the address of donk to blah(), but I don't understand the behaviour when I did. What seems to happen is that, in blah(), foo is cast to some kind of phantom Obj* which has not been constructed, but doesn't segfault when used. Why would it segfault? On most platforms an Obj and a pointer to an Obj are the same size, so you're passing blah an allocated chunk of memory of the correct size. If Obj had more than one field or if on your platform ints and pointers were different sizes this wouldn't "work".
|
# ¿ Jan 21, 2009 16:18 |
|
What does an abstract class with no public interface give you over just not inheriting at all? void doStuff(VehicleDealership vd) { ... } can't actually do anything with vd.floWenoL posted:What if someone has a PorscheDealership but add()s a non-Porsche car? It'd fail to compile because there is no add(Car *)?
|
# ¿ Feb 13, 2009 04:02 |
|
Getting torn to pieces is one of the most effective ways of learning from people on the internet due to how many people are far more willing to put effort into explaining why you're an idiot than answering a question. This has some unfortunate implications for people who don't like endless trolling, though.
|
# ¿ Mar 20, 2009 19:58 |
|
Avenging Dentist posted:for instance, cplusplus.com actually asserts that arrays are pointers.
|
# ¿ Mar 27, 2009 03:29 |
|
If you're fine with being windows-only, just use DirectShow. For other platforms, ffmpeg is the only particularly functional option, which you can use either by using libavcodec directly or by using a wrapper such as FFmpegSource.
|
# ¿ May 16, 2009 02:56 |
|
Why would you use longjmp/inline asm instead of just generating machine code which follows the appropriate calling convention then setting a function pointer to the appropriate address and calling it?
|
# ¿ Nov 23, 2009 00:38 |
|
http://en.wikipedia.org/wiki/Object_slicing Make ObjectManager::AddObj take a pointer to an Object instead and it'll work
|
# ¿ Dec 23, 2009 00:36 |
|
That's perfectly legal and there's even semi-valid reasons to want to do it, such as Duff's device. Switch requires that the first case statement (or default) comes before any expressions in switch's body, but nothing says that subsequent case statements cannot be inside other statements.
|
# ¿ Dec 23, 2009 09:01 |
|
MagneticWombats posted:What do people think about http://www.stepanovpapers.com/notes.pdf ? It's less mathy than most of his other stuff and it's kind of fun (and on a level, sad) to see the guy who did STL rail against the standards committee. On the other hand, for all his regrets, I wonder why he never made his own language or something.
|
# ¿ Dec 27, 2009 08:04 |
|
Copying and pasting comments is much worse than "silly". I think I'd describe it as more of "actively malicious", as it's pretty much guaranteed to result in incorrect documentation in one of the files at some point in the future. Personally I'd consider documenting stuff related to the public interface in the header file and everything else in the source file to be the only particularly sane option.
|
# ¿ Mar 24, 2010 18:08 |
|
The STL does have bind1st and bind2nd.
|
# ¿ Mar 29, 2010 22:30 |
|
They're awesome and fix most of my complaints with the language. I can't wait for a compiler to implement them.
|
# ¿ Mar 30, 2010 00:31 |
|
jonjonaug posted:Big hint: Everything up to and including "delete[] x;" is fine.
|
# ¿ Apr 19, 2010 07:20 |
|
cliffy posted:Really? There is never a good reason to hide the implementation of a template?
|
# ¿ Apr 28, 2010 21:24 |
|
washow posted:Hey goons! C++ student here!
|
# ¿ Apr 29, 2010 02:01 |
|
Ledneh posted:On another topic, because it came up in a discussion with coworkers earlier: is there any real argument to deciding when to pass around const pointers vs references besides "only use pointers when polymorphism is involved or said item can be null"?
|
# ¿ May 8, 2010 03:29 |
|
Vanadium posted:Worth pointing out that this only works within a class hierarchy with virtual destructors.
|
# ¿ May 8, 2010 14:08 |
|
Ledneh posted:is it C++ standard behavior to do nothing on a delete of a NULL/0 pointer Ledneh posted:why the hell have I been doing things like if (ptr) delete ptr; all these years?
|
# ¿ May 14, 2010 17:48 |
|
Johann Gambolputty posted:My question is if the debugger doesn't know the size, then how does the program know not to use the other addressed memory for the array.
|
# ¿ Jun 28, 2010 06:11 |
|
Define a strict total order for your class so that two different objects aren't equal.
|
# ¿ Jul 19, 2010 10:25 |
|
Debug runtimes don't come preinstalled and aren't licensed for redistribution, so if you haven't explicitly installed them or Visual Studio on a computer you can't run debug builds which dynamically link the runtime. Everything being linked together to form an executable needs to link against the same version of the runtime library. Switching only one thing between debug and release or static and dynamic runtime linking produces the linker errors you're seeing.
|
# ¿ Jul 19, 2010 23:31 |
|
In general, if you are linking against a library that you are compiling yourself you'll need to build both debug and release versions of it, and if you're linking against supplied binaries you have to hope that they're supplying binaries built in the configurations you need. Note that if you toss all of your dependencies into the solution with your project and set your project to depend on them (rather than building them separately and explicitly passing the .lib to the linker), visual studio does 90% of the work of ensuring that you're linking against the right things for you.
|
# ¿ Jul 20, 2010 00:06 |
|
There's really not much of a difference.
|
# ¿ Jul 21, 2010 21:05 |
|
Ledneh posted:I haven't tired it, but wouldn't lowercasing the whole key then checking for string equality against the (already lowercase) map key amount to the same CPU load as lowercasing character by character (which we're doing now)?
|
# ¿ Aug 2, 2010 08:04 |
|
Don't inherit from std::string. It doesn't have a virtual destructor and you can't safely use a lowercase_string as a string (e.g. static_cast<std::string&>(str) += "A" would break the invariant that all letters in the lowercase_string are lowercase).
|
# ¿ Aug 11, 2010 20:14 |
|
err.where<char>()
|
# ¿ Sep 7, 2010 07:43 |
|
epswing posted:Easy enough, but now this means to concat two strings, I can't just do "one" + "two", it needs to be
|
# ¿ Sep 16, 2010 19:50 |
|
Ledneh posted:One last (and more general) question, then. Does having a working garbage collector give the users carte blanche to comment out their deletes (and most destructors), since the GC will take care of it later? Or would counting on the GC as a rule cause a gross performance impact? (Or maybe even a performance boost, if destructors don't need to be called anymore? I don't know, I'm talking out of my rear end here.) In most cases it'll have no noticeable impact.
|
# ¿ Oct 1, 2010 00:48 |
|
Hammerite posted:If you refer to it in an integer context, you get the number of elements. You can assign an integer to set the number of elements. Hammerite posted:The book states that if you provide two overloaded versions of the subscript operator, one marked const and the other not, then the compiler is clever enough to use the appropriate one depending on whether the context is a reading or writing one; but from some simple experiments this didn't seem to be the case. (Using the GCC compiler included with Code::Blocks.) Some things I noticed while reading the code: C++ doesn't have a single nearly universal naming scheme like some languages do, but I've never seen camelCaps used for class names in C++ except for when it's a project-specific prefix. display, summary, total, mean, variance, and standardDeviation should be free functions which consume a myArray rather than members of the class, as they don't need access to myArray's privates. Similarly, the comparison operators don't need to be friended. You don't need the check for numberOfElements in the destructor, as deleting a NULL pointer is valid. The comparison operators would be simplified by just calling memcmp rather than looping over the arrays. Don't use const references to ints. It's slower and more typing than just passing an int by value and there's no advantage. There should be an assignment operator that takes a myArray.
|
# ¿ Nov 1, 2010 23:17 |
|
Yeah, you don't want to use memcmp; that was a dumb suggestion.Hammerite posted:How come? What are the two different versions used for? Plorkyeran fucked around with this message at 04:00 on Nov 2, 2010 |
# ¿ Nov 2, 2010 03:56 |
|
Please don't use GTK+ if you're ever planning to use the program on anything but linux.
|
# ¿ Nov 23, 2010 06:14 |
|
ToxicFrog posted:Why not? I've never had any problems releasing windows programs using GTK+.
|
# ¿ Nov 23, 2010 07:34 |
|
Fragaroc posted:A pretty simple question I think but I can't figure out if I'm doing anything wrong.
|
# ¿ Dec 9, 2010 22:05 |
|
pr0metheus posted:
Also, operator= should always return a reference to this so that chaining works. pr0metheus posted:I don't quite understand why -> operator works by just returning *. Can somebody explain semantics of it and why returning the pointer works? Plorkyeran fucked around with this message at 23:25 on Dec 9, 2010 |
# ¿ Dec 9, 2010 23:19 |
|
http://msdn.microsoft.com/en-us/library/bb432569.aspx is the documentation for the cabinet API. Getting a list of files in the cabinet appears to be fairly awkward: the extract all function (FDICopy) takes a callback which receives information about each file before it's extracted and can tell the extractor to skip extracting the file.
|
# ¿ Dec 10, 2010 00:27 |
|
Harokey posted:Is there a way to create an exception class, that when thrown (and not caught) prints a meaningful error message?
|
# ¿ Dec 15, 2010 02:10 |
|
GrumpyDoctor posted:Is there an idiomatic workaround for the fact that you can't use remove_if on STL maps because you can't reorder them? (Or, if you can, how do you do it?) code:
|
# ¿ Mar 10, 2011 00:19 |
|
Buffer overflows would be way less of an issue if they always caused crashes.
|
# ¿ Mar 30, 2011 00:40 |
|
|
# ¿ May 3, 2024 02:49 |
|
Templates (and things made possible by templates) are the only thing that makes coding in C++ even vaguely tolerable.
|
# ¿ Apr 10, 2011 05:59 |