|
Has anyone done anything serious with WTL, and if so do you have any comments on it? I've created a few noddy components/COM clients using ATL at work before, but I don't do much GUI stuff, so I'd like to give WTL a go for a project I'm working on in my spare time. I'm not entirely sure how to go about structuring my code though, since Microsoft doesn't really seem to do the whole MVC thing, and Win32's window messaging system gives me migraines. The cleanest thing I can come up with at the moment is to use CContainedWindowT everywhere, write controller mixins that respond to each CContainedWindowT's messages, then multiple-inherit the whole thing into a big master class which dispatches to the mixins via a big set of alternative message maps. Is this going to cause problems further down the line? I'd really like to use WTL though, simply because it has some very sexy and creative (ab)uses of C++, and it creates super-tight executables, which I love. Statically dispatched virtual function calls? Bring it on!
|
# ? Apr 15, 2009 21:49 |
|
|
# ? Jun 7, 2024 05:38 |
|
Lexical Unit posted:How you'd resize the window depends on a million factors. Sorry, you're right that was a horrible question. I'm using ncurses, and I want to have more room to put things in than the 80 x 25 I get default in windows. I know there is the resizeterm function, but I read you can't use that unless a couple of environment vars aren't set. Is there a way around that? EDIT: Nevermind, got it. Glasgerion fucked around with this message at 06:09 on Apr 17, 2009 |
# ? Apr 15, 2009 22:03 |
|
huge sesh posted:It's certainly not all the program's doing but it's really not that complicated. I don't allocate that much memory, page file is normal. std::vector works fine elsewhere in the program. I guess I'll look around for possible heap corruption. Just seems weird that it would happen every time. The simpler your program is, the more predictable your memory layout is likely to be (and any corruption to have deterministic effects), so it's not really weird at all . Take it a spin through Valgrind if you're on linux.
|
# ? Apr 15, 2009 22:23 |
|
Is there a way to basically have a templated object (this kinda breaks the point of templates, but humor me) that calls methods corresponding to its type? So i can basically call an overloaded method of function corresponding to its data type. Or am i just crazy.
|
# ? Apr 16, 2009 02:34 |
|
UberJumper posted:Is there a way to basically have a templated object (this kinda breaks the point of templates, but humor me) that calls methods corresponding to its type? How is what you want different from using inheritance with virtual functions? Or, how is what you want different from using typical overloaded functions?
|
# ? Apr 16, 2009 02:43 |
|
shrughes posted:How is what you want different from using inheritance with virtual functions? Or, how is what you want different from using typical overloaded functions? Sounds more like compile-time polymorphism (i.e. "generic functions"). UberJumper, post some code to show what you'd like to do, because I have no idea what you want right now.
|
# ? Apr 16, 2009 02:44 |
|
Avenging Dentist posted:Sounds more like compile-time polymorphism (i.e. "generic functions"). Sorry AD. Heres a terrible example (im exhausted) code:
Can i do this?
|
# ? Apr 16, 2009 03:12 |
|
UberJumper posted:Is there a way to basically have a templated object (this kinda breaks the point of templates, but humor me) that calls methods corresponding to its type? So i can basically call an overloaded method of function corresponding to its data type. Does template specialization sound like what you're looking for? code:
code:
|
# ? Apr 16, 2009 03:13 |
|
Fecotourist posted:Does template specialization sound like what you're looking for? Thats exactly what i was looking for. Thanks.
|
# ? Apr 16, 2009 03:26 |
|
Is there any way in C++ to duplicate the ability of C#'s System.Reflection.Assembly class to instantiate a class based on a string (so for example, passing in "CSomeObject" would return a pointer to a CSomeObject) without using what amounts to a gigantic if-then-else statement? Right now I have something like the following, and I'm trying to see if there's a way to not have to update that thing every time a new possibility is added to the system (pretend the names aren't obfuscated and there's like two dozen possible actions): code:
Ciaphas fucked around with this message at 16:37 on Apr 16, 2009 |
# ? Apr 16, 2009 16:32 |
|
Ledneh posted:Is there any way in C++ to duplicate the ability of C#'s System.Reflection.Assembly class to instantiate a class based on a string (so for example, passing in "CSomeObject" would return a pointer to a CSomeObject) without using what amounts to a gigantic if-then-else statement? You'll still need to have some table somewhere in your code that registers creation objects with the factory, but you can at least make it a bit less of a ball-ache. There are a few ways to make auto-registering objects, but it's a bit more involved, it usually doesn't save you much over the table solution, and you more often than not end up running into static initialisation ordering problems.
|
# ? Apr 16, 2009 16:45 |
|
Ledneh posted:Is there any way in C++ to duplicate the ability of C#'s System.Reflection.Assembly class to instantiate a class based on a string (so for example, passing in "CSomeObject" would return a pointer to a CSomeObject) without using what amounts to a gigantic if-then-else statement? Like said above, a factory is like what you are asking for. Maps and templated functions can help here. Here is my stupid example: code:
litghost fucked around with this message at 17:02 on Apr 16, 2009 |
# ? Apr 16, 2009 16:57 |
|
What's that old adage again? Any non-trivial project ends up implementing a significant subset of Smalltalk?
|
# ? Apr 16, 2009 17:10 |
|
Null Pointer posted:What's that old adage again? Any non-trivial project ends up implementing a significant subset of Smalltalk? Any sufficiently complicated C or Fortran program contains an ad-hoc, informally specified, bug ridden, slow implementation of half of Common Lisp. Including Common Lisp.
|
# ? Apr 16, 2009 17:57 |
|
I'm trying to compile a shared library that also happens to need a static library. How abouts would I do this? This is what I ran to compile my SO. code:
I am so confused . Please help.
|
# ? Apr 17, 2009 23:15 |
|
I've been working on an MFC program (ver. 6.0), and Am trying to implement a dialog box which will display before the main program. However, i've been having lots of trouble getting this to work. Any tips? Should the dialog box class be inside of the CFrameWnd class? other way around? I am trying to have the dialog box allow the user to select the size of the puzzle, which will call a function to set the size. Should I put the dialog class inside of the puzzle class? Any tips would be greatly appreciated.
|
# ? Apr 18, 2009 02:19 |
|
I'm trying to do a series of input questions, but am getting tripped up on using whitespace.code:
Whenever I enter something with whitespace, it fucks up everything. Here's sample output: quote:Please enter a number: 011 So I looked up noskipws and thought that would help, but it hasn't. When I try this: code:
quote:Please enter a number: 011 Please enter a name: Please enter a rank: Please enter the year: I just want some drat whitespace input in my character arrays, C++! Am I going to have to limit my prompts to single-strings? Like code:
|
# ? Apr 19, 2009 10:56 |
|
The regular formatted input you get using >> take every field as delimited by any whitespace. If you want to read an entire line into an std::string, you can use std::string my_line; std::getline(std::cin, my_line);. The exact thing that goes wrong for you is that it reads the first word as the rank, then leaves the rest of the input in a buffer. Then that buffer is used to instantly fill the rank variable without giving you a chance to enter anything else.
|
# ? Apr 19, 2009 11:18 |
|
Yeah, let go of the C++ dogma that says "just use cin and cout with << and >>, it's all you'll ever need". Sure, it's cool that those operators are overloaded, and that you can chain them because they return references to the stream, but any use beyond the truly trivial requires way too much other crap to work.
|
# ? Apr 19, 2009 16:51 |
|
operator<< and >> are neat for parsing or printing whatever. It is really just that commandline IO with all the buffering and error-flags-instead-of-exceptions and poo poo is unintuitive as gently caress and the operator>> that reads into std::strings is pretty useless.
|
# ? Apr 19, 2009 17:39 |
|
Been having some proof-of-concept fun with Eric Niebler's new mpl::string. Already posted about some of it on the Boost users' list, but didn't seem to garner any attention, so I'm posting it here in case someone gets a kick out of it. Compile-time itoa() metafunction: code:
code:
code:
code:
code:
|
# ? Apr 19, 2009 19:59 |
|
drcru posted:I'm trying to compile a shared library that also happens to need a static library. How abouts would I do this? quote:This is what I ran to compile my SO. A static library, on Linux, is just an archive of object files and doesn't contain linking information. Try this command: code:
|
# ? Apr 19, 2009 20:02 |
|
Vanadium posted:The regular formatted input you get using >> take every field as delimited by any whitespace. If you want to read an entire line into an std::string, you can use std::string my_line; std::getline(std::cin, my_line);. Fecotourist posted:Yeah, let go of the C++ dogma that says "just use cin and cout with << and >>, it's all you'll ever need". Sure, it's cool that those operators are overloaded, and that you can chain them because they return references to the stream, but any use beyond the truly trivial requires way too much other crap to work. Using cin.getline had the same result. I am using character arrays, though, not strings. Here is what I tried. code:
|
# ? Apr 19, 2009 20:26 |
|
getline doesn't consume newlines, so the input buffer after a newline looks like "\nbutts butts butts"... and so formatted input operations will assume you entered nothing.
|
# ? Apr 19, 2009 20:39 |
|
That was something I had seen and tried, too.code:
|
# ? Apr 19, 2009 20:46 |
|
cin and cout are completely independent. Nothing you do with cout will affect cin. Use istream::ignore.
|
# ? Apr 19, 2009 20:50 |
|
Alright, I'm feeling a little dumb here. It's been a couple years since I've programmed in C++ (I took two semesters of university courses), so I'm a bit rusty. I'm reading in a file and I keep getting a segfault when reading. Here's the code:code:
Input file: code:
code:
|
# ? Apr 19, 2009 22:31 |
|
code:
If you want to initialize an array to 0s when you define it, just say int my_array[666] = {}. If you want to zero it again later, use memset() instead of writing you own loop.
|
# ? Apr 19, 2009 22:41 |
|
Alman posted:
You have an off-by-one error here. The memory_values array has 992 elements, but the final pass of the loop sets the 993th element (memory_values[992]) to 0, which is messing up your stack. Edit: drat.
|
# ? Apr 19, 2009 22:43 |
|
Jesus dude, pick tabs or spaces, not both. Also if you're actually going to try to determine where something segfaults, you should be using cerr instead of cout. cout is buffered, and if the buffer isn't emptied before the segfault, you won't see all the data you printed. Also also, comments like "//Initialize all register values to 0" are kinda useless since the code isn't exactly long/complicated. Adding unnecessary comments is just a way of doubling the amount of maintenance you have to do when you decide to change something.
|
# ? Apr 19, 2009 22:45 |
|
Haha, wow. Thanks, I'm an idiot. Like I said, it's one of those things where it's been a while. Avenging Dentist posted:Jesus dude, pick tabs or spaces, not both. I wrote some of this at work, and for some reason the text editor I was using had some issues with tabs, so some of that got hosed up and I just haven't fixed it yet. Sorry! Also, regarding the stupid comments - I understand, it's just that I put them in there as insurance because the professor I'm handing this into is HUGE into documentation. torb main fucked around with this message at 23:16 on Apr 19, 2009 |
# ? Apr 19, 2009 23:13 |
|
Avenging Dentist posted:Also if you're actually going to try to determine where something segfaults, you should be using cerr instead of cout.
|
# ? Apr 19, 2009 23:15 |
|
Dijkstracula posted:If you're trying to determine where something segfaults, why are you not compiling with -g and running it through the debugger? I mean, that'll tell you more or less exactly what the problem is. As teapot has taught us (may he rest in peace), a debugger is the last refuge of the incompetent.
|
# ? Apr 19, 2009 23:17 |
|
Forgive me if this is a dumb question, but my experience with c is limited. So if I have a struct defined like this code:
code:
|
# ? Apr 20, 2009 08:35 |
|
riggsninja posted:But that puts it on the stack, right? If I need the array on the heap, is there a trick for doing something similar? Or once I malloc, do I need to go through arr[0].a = 1; arr[0].b = 2; arr[0].c = 3;... ? The closest you'll get (without knowing the size of the array at compile time) is something like: http://paste.ifies.org/461 (where I'm assuming you want to initialize each struct abc differently), but I'm pretty sure it's C99 only. Also, the fragment you posted isn't valid C; it would have to be "struct abc arr[] = ...". Are you in C++? floWenoL fucked around with this message at 10:20 on Apr 20, 2009 |
# ? Apr 20, 2009 10:17 |
|
riggsninja posted:But that puts it on the stack, right? If I need the array on the heap, is there a trick for doing something similar? Or once I malloc, do I need to go through arr[0].a = 1; arr[0].b = 2; arr[0].c = 3;... ? Well you can build the struct on the stack like you're doing, malloc() your destination heap memory, then memcpy() from stack to heap. Put that code in a function to clean up memory after. But that would be kinda roundabout. If your purpose is just to pretty your code, it doesn't really matter.
|
# ? Apr 20, 2009 10:28 |
|
Edit: Now my array is apparently empty.code:
I'm not sure how much of a difference this makes, but this is embedded SQL, and the way these variables are being declared is like this code:
Whilst farting I fucked around with this message at 13:48 on Apr 20, 2009 |
# ? Apr 20, 2009 13:23 |
|
Whilst farting I posted:No matter what I enter for a name, with whitespace or not, it never prints anything but blank spaces. This is such a trivial part of the program, too. Almost everything else is complete. I had it backwards, getline consumes newlines, >> does not. After using >>, you must do the following to make the stream usable for getline: code:
|
# ? Apr 20, 2009 15:50 |
|
The Red Baron posted:Compile-time itoa() metafunction:
|
# ? Apr 20, 2009 17:23 |
|
|
# ? Jun 7, 2024 05:38 |
|
Lexical Unit posted:Just curious, did you have some use case for writing this or was this just a "I wonder if I can..." type thing? Pretty neat either way.
|
# ? Apr 20, 2009 20:03 |