|
shodanjr_gr posted:I got a programming pattern question. If you're doing this on windows using visual studio, Detours can do this automatically.
|
# ? Sep 7, 2013 06:10 |
|
|
# ? May 27, 2024 06:37 |
|
What is the best kind of data structure for doing a gradebook? I was thinking of a vector of vectors, but that runs into problems when I want the first inner vector to be a vector of strings but the rest to be doubles.
|
# ? Sep 7, 2013 21:33 |
|
I don't know what a gradebook is or exactly what you want it to do, but it sounds like this:code:
|
# ? Sep 7, 2013 21:44 |
|
Rottbott posted:I don't know what a gradebook is or exactly what you want it to do, but it sounds like this: I think that might be a good start. Looks like I'll have to learn more about structs than just that they exist.
|
# ? Sep 7, 2013 22:12 |
|
hooah posted:I think that might be a good start. Looks like I'll have to learn more about structs than just that they exist. A struct is basically a public class that just holds variables. There you go.
|
# ? Sep 7, 2013 22:20 |
|
Are there any good things to read (books, blogs, magazine articles anything?) for an experienced C++03 developer wanting to learn what parts of C++11 are of daily use, vs what they should just be aware of in general? I know at a high level about a lot of them, but there's plenty of details I'm missing. Like when would you need to implement a move constructor. Or why you would want to invoke std::move vs just the assignment operator as two closely related examples.
|
# ? Sep 7, 2013 22:33 |
|
Hughlander posted:Are there any good things to read (books, blogs, magazine articles anything?) for an experienced C++03 developer wanting to learn what parts of C++11 are of daily use, vs what they should just be aware of in general? I know at a high level about a lot of them, but there's plenty of details I'm missing. Like when would you need to implement a move constructor. Or why you would want to invoke std::move vs just the assignment operator as two closely related examples. The newest version of the C++ Primer has a list of all the new stuff in the front, with what section the bits are covered by too. KNITS MY FEEDS posted:A struct is basically a public class that just holds variables. There you go. Can I define a struct within a class header? hooah fucked around with this message at 23:12 on Sep 7, 2013 |
# ? Sep 7, 2013 23:09 |
hooah posted:Can I define a struct within a class header? What the hell is a class header? It sounds like something your IDE invented, it's certainly not a concept C++ deals with. You can declare POD structs pretty much anywhere you want. Actually, that just made me think. Can you do this? C++ code:
|
|
# ? Sep 7, 2013 23:34 |
|
No.
|
# ? Sep 7, 2013 23:38 |
|
nielsm posted:What the hell is a class header? I meant in the header file. I tried it, and MSVC didn't complain. Rottbott, for that example struct you gave, how would I assign values to Name and Grades?
|
# ? Sep 7, 2013 23:44 |
|
I'm gonna dump code with absolutely no context.code:
|
# ? Sep 8, 2013 05:33 |
|
hooah posted:Rottbott, for that example struct you gave, how would I assign values to Name and Grades? What I'd do is create a constructor for the struct in addition to the variables; it would look something like this: code:
code:
Alternatively, you could manually initialize the values like so: code:
Pseudoscorpion fucked around with this message at 05:48 on Sep 8, 2013 |
# ? Sep 8, 2013 05:42 |
|
It's not really a C thing, there's nothing wrong with doing it that way. So long as the object is in a 'sensible' state after construction. In this particular case I'd probably use a constructor taking just the name, and fill in the grades later:code:
code:
code:
code:
|
# ? Sep 8, 2013 11:36 |
|
Thanks, guys, that's quite helpful. I am indeed a beginner, having only taken a 6-week summer class so far (enrolled in a second at the moment, but it's only been a week or so). I'd heard lots of advice to have side projects to show recruiters for internships/jobs, so since my wife is a teacher, I decided to start a program to keep track of grades (even though she probably won't use it).
|
# ? Sep 8, 2013 13:12 |
|
I was thinking of taking my home project from VS2010 C++ project into a Linux environment of some kind. I'm doing some stuff with OpenCL and I have been dragging more and more Boost stuff in since 2010 doesn't have any of the new language features. I also feel like all the supporting libraries I use are more popular in Linux than Windows. I was hoping for some advice in getting as many of these features as possible: 1. Baby me on Makefiles. Generally, my biggest problem has been forgetting to add files to the Makefile when I add a new file to the project, so a helper for that does a lot for me. 2. Sane error messages when I gently caress up templates, if that is at all possible. I heard clang is better about it than a lot of things. 3. Some autocompletion--as much as can be possible with C++, with some good ability to find usages and declarations of things. 4. Reasonable ability to compile back to Windows (deliberately vague). I was going to default to trying NetBeans with Clang.
|
# ? Sep 8, 2013 17:06 |
|
Rocko Bonaparte posted:2. Sane error messages when I gently caress up templates, if that is at all possible. I heard clang is better about it than a lot of things. 2. Clang is indeed the best. Super-latest versions of GCC are catching up a little in some respects (still not great about templates) 3. YouCompleteMe is hands down the best but you have to use Vim 4. Keep to the stuff here, I guess.
|
# ? Sep 9, 2013 00:53 |
|
SublimeText2 with the SublimeClang plugin is pretty awesome too. The interface is more similar to standard GUI text editors as well (i.e. tabs, Ctrl-xcv) but it's still super-duper powerful. Ctrl-p (quickly load any file in your project by typing the name) and ctrl-shift-f (regex searching of the entire project) are super-handy in particular. It's a text editor, not a full IDE though so you can't do things like step through with a debugger. gdb/lldb are pretty easy to pick up though and really amazingly nice though (although I don't know how well lldb does with c++) Another thing I've been doing lately is using inotify-tools to have a shell script that runs 'make test' every time I save a file in my tree. I just leave that going on a second monitor, all the time, and just look at it out of the corner of my eye.
|
# ? Sep 9, 2013 01:22 |
|
So I'm writing a game in C and considering rolling my own object/trait system for it and I'm wondering just how bad of an idea this is/if there's anything fundamentally wrong with how I'm thinking of implementing it. My basic idea is to use a standard vtable for everything like so: C++ code:
C++ code:
C++ code:
C++ code:
I'm kinda posting this here to see if anyone has input on this, like if I'm missing anything obvious or if anyone has any suggestions (or to see if I'm crazy). Note: I don't want to write it in C++. I just don't. I know it'd be easier in C++, but I wanted to write something in plain C. Look Around You fucked around with this message at 05:39 on Sep 9, 2013 |
# ? Sep 9, 2013 05:33 |
|
By having a copy of the full vtable in every object, you're making them much larger unnecessarily. C++ objects store a pointer to a vtable instead, it's an extra indirection when calling methods, but you only need one global copy of each unique vtable layout (e.g. monster, player). I would do it that way to begin with. If you want to get fancy, Andrei Alexandrescu's recent talk at GoingNative had interesting stuff about DIY vtables - he's talking C++ but the code is essentially C. See here, in particular the slide about 'vertical tables' at 42:00.
|
# ? Sep 9, 2013 09:24 |
|
Having a weird issue that someone can probably enlighten me on real quick. See: https://github.com/toulouse/ATLeagueUtility/blob/master/src/main.cpp#L36 Without the "new" on line 36, I get an error: "Call to implicitly-deleted copy constructor of 'AT::RAF::Archive". The constructor is defined as "Archive(const string &archiveFilename);", which shouldn't be a copy constructor, right? Even with "Archive(const Archive &) = default;" added on to the Archive class's declaration, it seems to think the copy constructor has been implicitly deleted, and that the call to it is invalid. What's going on? Does C++ have problems overloading constructors that take a reference type?
|
# ? Sep 10, 2013 06:41 |
|
Doctor w-rw-rw- posted:Having a weird issue that someone can probably enlighten me on real quick. code:
In this case, the copy constructor is implicitly deleted since the member ifstream is non-copyable, and that syntax requires a copy (or move) constructor to be available (even if it may not be called by the compiler). I'm almost positive that ifstream is moveable, though, so depending on your comfort with move operations, saying "Archive(Archive&&) = default;". But unless you're secretly Herb Sutter and have a crazy obsession with using auto for everything, "Archive archive(archiveFilename);" would work just as well.
|
# ? Sep 10, 2013 07:36 |
|
limip posted:For explicitness I assume that you mean: Yes, that's what I mean, and I'm afraid I don't quite understand. How is Archive(ifstream) a copy constructor if it's not even an Archive, or am I misunderstanding what a copy constructor is? I'm approaching this from a background in C/ObjC,Java/etc., so I'm positive I have a hole in my knowledge. (I did take your advice to fix it, though, thanks!)
|
# ? Sep 10, 2013 09:20 |
Doctor w-rw-rw- posted:Yes, that's what I mean, and I'm afraid I don't quite understand. How is Archive(ifstream) a copy constructor ifkp it's not even an Archive, or am I misunderstanding what a copy constructor is? I'm approaching this from a background in C/ObjC,Java/etc., so I'm positive I have a hole in my knowledge. Your Archive class likely holds an ifstream object as member. The default copy constructor copies all members of the class one by one. If one of the members can't be copied then the compiler can't generate the default copy constructor. The ifstream class can't be copied, therefore an Archive class with one as member can't have a default copy constructor. (Sorry about going all basic logic here, but I hope it explains. At least it's how I understood it.)
|
|
# ? Sep 10, 2013 09:51 |
|
nielsm posted:Your Archive class likely holds an ifstream object as member. The default copy constructor copies all members of the class one by one. If one of the members can't be copied then the compiler can't generate the default copy constructor. The ifstream class can't be copied, therefore an Archive class with one as member can't have a default copy constructor. The problem was the the poster didn't understand why a copy constructor would be needed at all. The distinction is the = used in the variable declaration. C++ code:
C++ code:
seiken fucked around with this message at 10:54 on Sep 10, 2013 |
# ? Sep 10, 2013 10:44 |
|
seiken posted:The problem was the the poster didn't understand why a copy constructor would be needed at all. The distinction is the = used in the variable declaration. That is incorrect. That first expression should use a move constructor at most, and a default initialization at least. (as the expression on the right is an rvalue) unless the compiler being used is some visual studio version in which case ignore me, as visual studio doesn't follow the new standard. EDIT: wow, I double quoted somehow? Slurps Mad Rips fucked around with this message at 20:32 on Sep 10, 2013 |
# ? Sep 10, 2013 15:31 |
|
Nope, LLVM 3.3 on C++11 with libc++. Enlightening stuff. Thanks!
|
# ? Sep 10, 2013 17:33 |
|
I'm writing a thing. It forks and execs stuff. It will join children if they terminate before the parent, but otherwise I just want it to ignore them. The child does: code:
[user@whatever dir]# -bash: asdf: command not found [user@whatever dir]# Instead of: [user@whatever dir]# asdf -bash: asdf: command not found [user@whatever dir]# Messing around trying to fix this, I added a close(0) before execve() to close stdin. This fixes all the terminal weirdness, and I can Ctrl-c the parent, but it takes the children down with it! If I signal the parent from somewhere else, the children keep on truckin. What have I most likely hosed up?
|
# ? Sep 10, 2013 17:44 |
|
Here's code demonstrating standard C++11 behavior: http://coliru.stacked-crooked.com/a/021dbd912b88f189 Note that the copy constructor of ContainsMoveOnly is implicitly deleted due to having a member of type MoveOnly Not sure what the issue is if you're compiling with LLVM 3.3 using the "-std=c++11" flag. I'm stuck with LLVM 3.2svn and the code I posted above compiles just fine. (it only complains about unused variables) EDIT: You've defined a copy constructor/operator in your class. Define a move constructor/operator, and the problem should go away. EDIT 2: No, it won't. Your version of libc++ isn't standards compliant. std::ifstream is move-constructable, but it wasn't in older versions. If you download the latest version, it should compile fine. The Laplace Demon fucked around with this message at 20:05 on Sep 10, 2013 |
# ? Sep 10, 2013 18:02 |
|
Illusive gently caress Man posted:Messing around trying to fix this, I added a close(0) before execve() to close stdin. This fixes all the terminal weirdness, and I can Ctrl-c the parent, but it takes the children down with it! If I signal the parent from somewhere else, the children keep on truckin. When you fork(), the children inherit a copy of the parent's file descriptors, so the children may have been grabbing your terminal from you when they inherited fd 0. As for Ctrl+C, this looks like what normally happens. It sounds like you're not catching SIGINT to override the normal behavior, except for when you mentioned signaling from somewhere else. How are you signaling the parent otherwise?
|
# ? Sep 10, 2013 18:28 |
|
contrapants posted:When you fork(), the children inherit a copy of the parent's file descriptors, so the children may have been grabbing your terminal from you when they inherited fd 0. I have a handler for SIGINT/SIGTERM, so I just use kill in another terminal. Obviously when the children execve, they lose that handler (which is what I want anyway). What do you mean by 'what normally happens' regarding Ctrl-C? Why are children responding to Ctrl-C after I close fd 0? Is closing fd 0 the right way to do this? Should I open /dev/null and dup it to 0 instead?
|
# ? Sep 10, 2013 18:39 |
|
Illusive gently caress Man posted:Why are children responding to Ctrl-C after I close fd 0? Is closing fd 0 the right way to do this? Should I open /dev/null and dup it to 0 instead? Signals don't come through stdin, you need to detach the children from the controlling terminal, eg. with setsid
|
# ? Sep 10, 2013 18:47 |
|
hackbunny posted:Signals don't come through stdin, you need to detach the children from the controlling terminal, eg. with setsid Thanks, that's exactly what I needed.
|
# ? Sep 10, 2013 18:51 |
|
SAHChandler posted:This is incorrect, and only applies to c++03 or compilers that lack uniform initialization. SAHChandler posted:For instance, lambdas are noncopyable, so in the case of the first expression, were it to be a lambda it would simply not compile. SAHChandler posted:That is incorrect. That first expression should use a move constructor at most, and a default initialization at least.
|
# ? Sep 10, 2013 19:16 |
|
That Turkey Story posted:No. Seiken really is correct. A compliant compiler is allowed to optimize away the copy or move operation and construct the object in place. This is correct. To elaborate, auto x = MyClass{}; or auto x = MyClass(); will construct MyClass using MyClass::MyClass(), and then using either the copy/move constructor/operator, will copy/move it into x. If the user hasn't defined any copy/move constructors/operators, the prvalue will be moved into x assuming all members of MyClass are moveable types. If not, then it will be copied if all members are copyable types. If not, you get an error. If the user has defined a copy constructor/operator, the prvalue will be copied into x using that. If it is the default, this only occurs if all types are copyable. Otherwise, you get an error. If the user has defined a move constructor/operator, the prvalue will be moved into x using that. If it is the default, this only occurs if all types are moveable. Otherwise, you get an error. If the user has defined both copy and move, then the prvalue is moved. In practice, the compiler will probably just construct your type in place. But both copy and move cannot be deleted, explicitly or implicitly. EDIT: nothing to see here The Laplace Demon fucked around with this message at 20:05 on Sep 10, 2013 |
# ? Sep 10, 2013 19:52 |
|
That Turkey Story posted:It is still allowed to be optimized away in C++03 and C++11, and compilers do so (it also doesn't matter how complicated the type or its copy/move is). The appropriate constructor still needs to be able to be called though. I somehow managed to post the one response that I realize was wrong (about the lambdas). I could have sworn I deleted it (was posting from the awful app), but it went through anyhow. That explains the double quote. I know they can optimize it away, but I believe I had read the message where most cases wasn't in the message (I definitely don't remember it being there). Basically I hosed up, ignore what I said
|
# ? Sep 10, 2013 20:35 |
|
More confusion, this time over how to read only a specific range of an ifstream.C++ code:
I have no clue what arguments to feed to copy_n to make it work, or whether this is the right approach in the first place. Should I just be reading into a char vector and back out? EDIT: After stepping away I wonder if I should just use the ifstream to read into a vector instead of doing this stupid crap with streams, because it'd have to allocate the same or more amount of memory anyway to convert it from gzip to raw. Should get me most of the way to the next error in my code... EDIT 2: I am at a complete loss for how to decompress the bytes into another vector array. :/ EDIT 3: nevermind, got it: https://github.com/toulouse/ATLeagueUtility/commit/9ac9069c1afe7adfa2b8b8023e87e9dcc3fe3c70. It feels like C++ will never get any easier Doctor w-rw-rw- fucked around with this message at 09:02 on Sep 11, 2013 |
# ? Sep 11, 2013 07:55 |
|
Edit: wrong thread.
|
# ? Sep 13, 2013 00:59 |
|
Are there any good JSON libs for C?
|
# ? Sep 15, 2013 01:04 |
|
I'd have a look at https://wiki.gnome.org/JsonGlib/ if you don't mind bringing in Glib land.
|
# ? Sep 15, 2013 02:13 |
|
|
# ? May 27, 2024 06:37 |
|
JSON GLib is an amazing library, if only for its integration with GVariant, which is kick-rear end. But if you're not a glib fan it's probably not for you.
|
# ? Sep 15, 2013 03:09 |