|
If you make a separate C thread please make sure it's worth it first...I'm able to talk C/POSIX here with only a little added scrolling, which is absolutely fine. What I wouldn't want is the C++ programmers we depend on telling us to go back to the C-only thread that nobody contributes to.
|
# ? Jul 21, 2010 20:28 |
|
|
# ? Jun 8, 2024 15:02 |
|
Ugg boots posted:Pro-tip since you're new to the thread, Crazy RRRussian is a fakeposter who has been around these parts for a while under different names (Hexadecimal, Entheogen, ...)
|
# ? Jul 21, 2010 21:03 |
|
There's really not much of a difference.
|
# ? Jul 21, 2010 21:05 |
|
Haters gonna hate, and that was a serious question I had, not a fakepost!
|
# ? Jul 21, 2010 21:54 |
|
If you know in advance which class(es) and member function(s) you need to be able to call "reflectively" you could use a factory and a static map from string to member function pointer to simulate it. This works for virtual member functions too; your compiler will generate code to do a runtime vtable lookup so it will work exactly like if you called it without the indirection.
|
# ? Jul 22, 2010 05:10 |
|
Mr.Radar posted:If you know in advance which class(es) and member function(s) you need to be able to call "reflectively" you could use a factory and a static map from string to member function pointer to simulate it. This works for virtual member functions too; your compiler will generate code to do a runtime vtable lookup so it will work exactly like if you called it without the indirection. Is there any automated way of doing this? like via some crazy macros to generate such a map?
|
# ? Jul 22, 2010 14:35 |
|
Crazy RRRussian posted:Is there any automated way of doing this? like via some crazy macros to generate such a map? boost::fusion can make tuples of structures. See BOOST_FUSION_ADAPT_STRUCT. I am not sure that you can get the name of the field through, you would need to try it out.
|
# ? Jul 22, 2010 15:54 |
|
Should this compile or not?code:
|
# ? Jul 22, 2010 20:58 |
|
Ahahaha. This is the most terrible thing in the world. So, the compiler has to decide whether the '<' in "lhs . list <" starts a template-id. If the type of 'lhs' is dependent (and not a current instantiation), then it can't just look into that type. You would think that the appropriate thing to do here would be to require the 'template' keyword, which is indeed required in other, similar contexts, but no: instead the standard requires us to look up the identifier in lexical scope to see whether it names a template. In this case, it does, so just in case you're trying to say "lhs.list<T>::blah" the compiler continues to parse that as a template-id. Of course that won't work because it's syntactically malformed; however, apparently before it figures that out, gcc complains about how "rhs.list" (which it's just parsed as a non-type template argument) is not a constant expression, and then stops there. The solution is to parenthesize lhs.list.
|
# ? Jul 22, 2010 21:21 |
|
Oh duh. The fact that it was looking for a constant expression should have clued me into the issue with parsing <, especially since the compiler had no issue with the other defined operators.
|
# ? Jul 22, 2010 21:27 |
|
I'm having a bit of trouble with this:code:
|
# ? Jul 22, 2010 21:42 |
|
I don't believe you that this function loops forever. I do believe that it only generates one line, though, because i goes from 0 to 499, and then you fall out of the loop and return. And I can believe that your program loops forever if you call this function in a loop, passing in a variable called 'y' and expecting it to be modified in the calling function. I think you don't really understand local variables. Also, that store to 'y' will never, ever be executed. rjmccall fucked around with this message at 21:52 on Jul 22, 2010 |
# ? Jul 22, 2010 21:49 |
|
I can't say I do. this is my first serious project with any programming language, and I haven't taken any classes or anything on it. Thanks for the kinda-help though. Foran fucked around with this message at 21:56 on Jul 22, 2010 |
# ? Jul 22, 2010 21:54 |
|
Rsugar posted:I can't say I do. this is my first serious project with any programming language, and I haven't taken any classes or anything on it. Thanks for the kinda-help though. The y in your function is a local variable. If you do: code:
MagneticWombats fucked around with this message at 22:28 on Jul 22, 2010 |
# ? Jul 22, 2010 22:25 |
|
Thanks, that bit of info helped fix the problem.
|
# ? Jul 23, 2010 00:46 |
|
MagneticWombats posted:The y in your function is a local variable. If you do: Also "x" as the input parameter get overwritten immediately, losing any info the param holds. Re-engineer your function matey. Crazy Russian, any luck on your c++ reflection project ?
|
# ? Jul 23, 2010 01:02 |
|
I'm kind of puzzled by the typing of rectangular arrays. I've been messing around with a test program and I'm mostly looking for a confirmation as to whether I've come to the right conclusions.code:
If, instead of using a rectangular array, I use a char **, I can use the double [][] notation again. I've been messing around with MSVC's debugger, as well as generated assembly trying to figure out how each type is stored and looked up. Obviously, the [][] notation is completely different in a rectangular array from an array of arrays. I understand how the array of arrays works, and the double lookup that follows. What I'm not sure about is the rectangular array. From what I can tell, the rectangular array lookup is translated into a simple, dumb copy directly from the right position in the stack. Given this, I'm assuming the [][] notation is just syntactic sugar from the compiler for rectangular arrays, which get translated into offsets on the stack. Since the real meaning of [] is a pointer lookup rather than a stack offset, that kind of lookup fails if I cast cStack to a char ** like this: code:
Given all this, is it safe to assume that the compiler will never let me cast something back into a char[4][3] type as I'm attempting to do in the commented lines? Or is there a syntax I haven't figured out that could do that?
|
# ? Jul 23, 2010 02:29 |
|
Remember that pointers are not arrays; they types you're casting from are distinct. Here's an illustration that's hopefully intuitive: T **pp is a pointer to an element of an array of pointers, and T (*pa)[N] is a pointer to an element of an array of arrays. pp + 1 will be sizeof(T*) bytes from pp. pa + 1 will be sizeof(T[N]) bytes from pa. Also keep in mind that this distinction doesn't have anything to do with stack versus heap. If you wanted to dynamically allocate a 2-dimensional array, it'd be something like char (*p)[5] = new char [x][5];
|
# ? Jul 23, 2010 03:50 |
|
Ah, figures, I looked through the C++ FAQ but didn't think to look for a C FAQ for, well, C-like issues. Thanks, that should help me figure things out.
|
# ? Jul 23, 2010 05:33 |
|
Running into an initialization problem due to the way some of my classes are setup. Here are the relevant constructors, boiled down to their basics:code:
code:
I'm trying to do everything according to RAII and it's been working great so far, but I don't know how to fix this without fundamentally breaking that design.
|
# ? Jul 23, 2010 20:28 |
|
If you want to maintain this exact interface, and file handles aren't movable, then you'll need to derive from a private base class which holds the handle: class FileTrack : private FileHandlerHolder, public Track {...};
|
# ? Jul 23, 2010 20:47 |
|
FileTrack::FileTrack(const std::string& filename) : Track((new (&_file) WhatEverFileIs(filename))->channels())
|
# ? Jul 23, 2010 21:08 |
|
I feel like we can safely assume that WhatEverFileIs isn't trivially constructable and destructable.
|
# ? Jul 23, 2010 21:29 |
|
That's the strangest use of a placement new I've ever seen. Private inheritance works like a charm, thanks for reminding me of its existence!
|
# ? Jul 23, 2010 21:33 |
|
rjmccall posted:I feel like we can safely assume that WhatEverFileIs isn't trivially constructable and destructable. Does it count if we derive from it and give the new class a special constructor that does nothing?
|
# ? Jul 23, 2010 21:42 |
|
The new class's constructor would still need to (implicitly) construct its base class. I think you could make this work with something like: code:
|
# ? Jul 23, 2010 22:48 |
|
Vanadium posted:FileTrack::FileTrack(const std::string& filename) That is worth 8 hrs man time ripping out and re-testing on it's own. Do it for the good of the community
|
# ? Jul 24, 2010 00:19 |
|
I'm trying to tweak the way a Qt widget works. (Long story short: I'm trying to add validation to the edit mode of a QListView.) After looking over the (LGPL'ed) source, I've come to the conclusion I'm going to have to alter how a particular function works. Problem is, this function isn't virtual. I could just wrap the function in a sub-class function, but the super-class function is called from a few different places inside the super-class, so that's no good. What's the best way to do this? If I override this non-virtual function in the sub-class, and promise never to polymorphisize it, will the function calls in the super-class still hit on the non-overridden super-class version of the function? I know that's not the best idea, even if it does work, but the only other thing I can think of is to copy+paste the whole drat 4,000+ line source for the QListView (well, technically QAbstractItemView) widget, add the keyword "virtual" to the function, and rename the class. Aside from the PITA aspect, I'll then lose out on future updates to the class put out by Trolltech/Nokia -- essentially locking me in to the current release of Qt.
|
# ? Jul 25, 2010 11:49 |
|
If you want custom validation in a Qt MVC widget, you can create and set a delegate that overrides the createEditor method; see http://doc.qt.nokia.com/latest/model-view-delegate.html#providing-an-editor And no, you can't override a non-virtual and have the superclass call the child class version. It's impossible.
|
# ? Jul 25, 2010 16:20 |
|
OddObserver posted:And no, you can't override a non-virtual and have the superclass call the child class version. It's impossible. Er... code:
A::foo B::foo
|
# ? Jul 25, 2010 16:28 |
|
That's not the superclass calling the child version. You're calling the child version, which in turn calls the parent version. I was sort of wrong considering the whole: class ChildClass: public Foo<ChildClass> pattern, though, but that doesn't apply here anyway (I was thinking of a -fixed- base)
|
# ? Jul 25, 2010 16:35 |
|
Oh, duh. I was just waking up and hadn't taken my morning coffee, I completely mixed up the terminology. Yeah, nevermind. I can't see how you could do that short of using ugly memory replacement hacks.
|
# ? Jul 25, 2010 17:00 |
|
I have to output a bunch of data in a format that is readable by an analysis program. After some trial and error, I've figured out that the program parses data by using field width rather than a delimiter (it reads a value every ten characters) but I'm having trouble outputting in this format. The simplest way to do it, I figure, is to output each datum with seven digits before the decimal place and one figure after (I only need 1 d.p. precision) plus a space to delimit data elements, thus giving a total of 10 characters. I'm doing the work in MATLAB and using the 'dlmwrite' function which allows modification of the precision attribute. From the dlmwrite help file: code:
|
# ? Jul 26, 2010 00:23 |
|
Daviclond posted:Well this isn't really a MATLAB thread but I think the problem isn't your formatting string but rather that dlmwrite doesn't actually use string formatting. Try fprintf instead.
|
# ? Jul 26, 2010 00:28 |
|
Jan posted:Well this isn't really a MATLAB thread but I think the problem isn't your formatting string but rather that dlmwrite doesn't actually use string formatting. Try fprintf instead. That function uses the same formatting style, but happens to mention you can prefix the field value with a space or a zero to pad it with spaces or zeroes. Putting '% 9.1f' instead of '%9.1f' (apparently the field length refers to the entire number, so I wanted a 9 not a 7) into the dlmwrite function gives me the required output, thanks
|
# ? Jul 26, 2010 00:48 |
|
(I know this thread isn't about .NET, it's just context for what is really just a C++ question) C++/CLI allows mixing native types with managed types, so long as they are pointers or references. Now I have a class which wraps a native type, with a 1:1 composition relationship. If it wasn't for the C++/CLI mixing restriction, I'd just make it a member variable, but since it has to be a reference or pointer, I'm faced with 2 alternatives: A const pointer: code:
code:
|
# ? Jul 27, 2010 17:16 |
|
beep boop
handsome only face fucked around with this message at 22:40 on Jul 27, 2010 |
# ? Jul 27, 2010 17:23 |
|
Jan posted:Is there any reason not to go with the fake reference? I know references are essentially supposed to alias existing objects, but using this syntax is really aliasing a new object that doesn't exist anywhere else, which is not really the intent of references. There is absolutely nothing wrong with binding a reference to a heap object that the reference "owns". You do have to watch out for the pointer being null, but in this case (assuming you're using exceptions) that should not be possible.
|
# ? Jul 27, 2010 18:04 |
|
"Avenging Dentist" in March posted:Timothy Madden is desperately clinging to a language feature that even he acknowledges isn't actually that useful.
|
# ? Jul 27, 2010 21:28 |
|
|
# ? Jun 8, 2024 15:02 |
|
Are there any hard-and-fast rules I can use for when STL container iterators can become invalidated/shouldn't be used anymore? Things like inserting/erasing while iterating, resizing, whatever. It seems like the rules change every goddamn time I have to debug something, and my google-fu is proving weak except for some PDF that has few real examples. Running into a goofy bug with a find() call on a map causing a segfault and it's really aggravating, I'm kind of flailing hoping I have a screwed up iterator somewhere at this point
|
# ? Jul 30, 2010 08:27 |