|
DoctorTristan posted:Am I right in thinking that if I have a class with a public static member, I should always initialise it in a .cpp file and not in the header?
|
# ? May 12, 2009 13:18 |
|
|
# ? Jun 7, 2024 06:29 |
|
Mustach posted:Yes, only constant integral types can be initialized in the class declaration/header (until C++0x). And then when C++ gets a module system, it'll change all over again!!!
|
# ? May 12, 2009 17:50 |
|
Ugh don't remind me of how badly I want modules in C++.
|
# ? May 12, 2009 18:32 |
|
C99: Is the following statement true or false? It is impossible to portably call the following function with integer literals, without casting, and with a non-zero first argument. code:
code:
code:
|
# ? May 13, 2009 00:53 |
|
Incorrect. Variadic arguments are subject to the rules of default argument promotion (float -> double, and smaller integer types converted up to int or unsigned int). EDIT: note that this means integral types larger than int retain their size and require knowledge of their types to be dereferenced. See §7.15 of the ISO standard. Avenging Dentist fucked around with this message at 01:27 on May 13, 2009 |
# ? May 13, 2009 01:13 |
|
Avenging Dentist posted:Incorrect. Variadic arguments are subject to the rules of default argument promotion (float -> double, and smaller integer types converted up to int or unsigned int). I don't think default argument promotion applies here: the interesting arguments are decimal integer literals which are always at least ints (6.4.4.1). Avenging Dentist posted:EDIT: note that this means integral types larger than int retain their size and require knowledge of their types to be dereferenced. See §7.15 of the ISO standard. Exactly! In the examples: code:
quote:If there is no actual next argument, or if type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined, except for the following cases:
|
# ? May 13, 2009 01:51 |
|
ctz posted:I don't think default argument promotion applies here: the interesting arguments are decimal integer literals which are always at least ints (6.4.4.1). Then you use ints and not size_ts, which honestly is a pretty bad idea to begin with. Or you do the right thing and pass a format string. Or the even righter thing and use C++ templates. You might be able to fix it with variadic macros, but it would be non-trivial. Avenging Dentist fucked around with this message at 02:10 on May 13, 2009 |
# ? May 13, 2009 01:55 |
|
The Final Solution, using Boost.Preprocessor:code:
code:
|
# ? May 13, 2009 03:07 |
|
In C++, static global functions are static in the C way right? As in can be only used by that c/cpp file and not externed? I'm pretty sure this is true I just want to make sure there isn't some special C++ thing going on since static seems to have about 17 different uses.
|
# ? May 13, 2009 05:29 |
|
Contero posted:In C++, static global functions are static in the C way right? As in can be only used by that c/cpp file and not externed? I'm pretty sure this is true I just want to make sure there isn't some special C++ thing going on since static seems to have about 17 different uses. Yes. But the idiomatic C++ way is to use an anonymous namespace.
|
# ? May 13, 2009 05:48 |
|
Yes but the more "C++ way" is use the anonymous namespace instead. namespace{ /* whatever */ } edit: bah, and I even almost said "idiomatic," too
|
# ? May 13, 2009 05:48 |
|
That's exactly the kind of thing I was hoping to hear! Thanks.
|
# ? May 13, 2009 05:58 |
|
Last night I was playing around in C++, I'm a total beginner but I was thinking about how an X-COM or FFTactics style game could be made. I figured the "map" would probably be a 3-dimensional array. Or 4-dimensional, if I wanted to store a bunch of data for each cell? But I guess it would be cheaper to make each entity contain it's own data and position in space than have all that blank data where there's nothing going on. I'm just musing here, if anyone wants to add anything or throw any concepts at me before I get my head going down the wrong path. I've also played around with writing to the screen buffer while doing Wii homebrew, like how to draw an image or a box, so for now I've stared with a two dimensional array and I'm dicking around with "drawing" numbers to it, and printing it out as a "screen" of numbers as "pixels". Eventually from a 3-dimensional array I'll try to create functions to draw cubes and triangles at whatever size I want, etc. Anyhow, I've been having some strange errors come up. I have 2 const ints for the "resolution" of the array (which is called "scrn") that I can set before compiling. If I set them both to four (so including 0 it's a 5x5) and I set scren[2][2] to 1 (while all the others are 0) it looks like this: code:
code:
EDIT: Now that I think about it there's still the possibility that it's in the prntScreen function, which goes along and writes what's at X/Y to screen increments X and writes again until it reaches the end of the "line", then increments y and resets x to 0, repeat. That's probably it. Bah. fart barterer fucked around with this message at 19:35 on May 14, 2009 |
# ? May 14, 2009 17:08 |
|
androo posted:If I set them both to four (so including 0 it's a 5x5) I think you need to read up on some basic C++ array stuff, because an_array[4][4] does not yield a 5x5 including the 0th place.
|
# ? May 14, 2009 21:51 |
|
Ahhhh, I remember the days when I used to think that the array was the only data structure in the world.
|
# ? May 14, 2009 21:54 |
|
androo posted:(which is called "scrn") Don't. Just... don't. The extra letters needed for "screen" and "printScreen" never hurt anyone, you've got plenty of disk space available for sourcecode, and you need all the extra readability you can get.
|
# ? May 15, 2009 08:15 |
|
Avenging Dentist posted:Ahhhh, I remember the days when I used to think that the array was the only data structure in the world.
|
# ? May 15, 2009 20:23 |
|
Morton the Mole posted:I think you need to read up on some basic C++ array stuff, because an_array[4][4] does not yield a 5x5 including the 0th place. Doh, I'll look that up then. Vinterstum posted:Don't. Just... don't. The extra letters needed for "screen" and "printScreen" never hurt anyone, you've got plenty of disk space available for sourcecode, and you need all the extra readability you can get. Hah, good point. It's just nice to bang them out really quick while typing, and I never know when something else could be using those terms I guess? Avenging Dentist posted:Ahhhh, I remember the days when I used to think that the array was the only data structure in the world. I love working with arrays because they're so drat simple (and in terms of tiled 3D space, they're perfect for a beginner like me) but if you can tell me what you started picking up afterwords that would be sweet.
|
# ? May 16, 2009 01:00 |
|
androo posted:I love working with arrays because they're so drat simple (and in terms of tiled 3D space, they're perfect for a beginner like me) but if you can tell me what you started picking up afterwords that would be sweet. Arrays are nice, but depending on what you are doing there could be much better alternatives. What you are doing looks just right for arrays since you can't get any better, but if you are interested in other data structures then take a look at the C++ STL. A good choice in data structure can mean the difference between your algorithm taking minutes over milliseconds, but they all have different uses.
|
# ? May 16, 2009 02:07 |
|
Does anyone know anything about decoding wma files so that I can get the samples from their wav form? I have done it with mp3s, but I don't see much documentation on wma files and google just shits out a bunch of "free decoder" stuff when I try and search for it... any help would be appreciated.
|
# ? May 16, 2009 02:21 |
|
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 |
|
androo posted:I love working with arrays because they're so drat simple (and in terms of tiled 3D space, they're perfect for a beginner like me) but if you can tell me what you started picking up afterwords that would be sweet. quote:Or 4-dimensional, if I wanted to store a bunch of data for each cell? code:
What you want is closer to this: code:
|
# ? May 16, 2009 16:49 |
|
Dijkstracula posted:
I'm a C++ scrub, but will this: struct tile world[256][256]; lay out in memory the same as this: struct tile world[256*256];? I always get confused with C++'s pointer vs. array stuff.
|
# ? May 17, 2009 00:49 |
|
Ugg boots posted:I'm a C++ scrub, but will this: They both occupy the same amount of space in a contiguous block of memory. Multidimensional arrays are row major.
|
# ? May 17, 2009 03:14 |
|
That Turkey Story posted:They both occupy the same amount of space in a contiguous block of memory. Multidimensional arrays are row major. That's what I was wondering (the contiguous block of memory.) I assumed so, but I've learned never to assume anything about C/C++. Thanks.
|
# ? May 17, 2009 05:47 |
|
If I have a class containing pointers to other objects and a destructor that destroys the other objects, will this in turn call the destructors of the objects below it (which would be set up to destroy those and any they contain)? Is there a better way to do this or is that okay? e; Think I answered my own question. It's a fastcgi application and memory usage is staying constant regardless of usage. Murodese fucked around with this message at 12:13 on May 17, 2009 |
# ? May 17, 2009 11:34 |
|
what is the best way to read data from a file? I have a file with a bunch of numbers in a line... such as '2410 1 3832 3 2838 2 123 1' I need to read each number and store it in a variable. so far i have tried streaming it in but it only gets each single digit. i am trying to get each number and stop at the space.
|
# ? May 19, 2009 04:50 |
|
code:
|
# ? May 19, 2009 04:53 |
|
well the problem is that i have to store the data in a structure as well. pretty much i have to read from the text file a number followed by an integer from 1-3. then i store that in a structure. once it is in the structure the amount will get added or subtracted depending on the integer code. in the file there are spaces between the numbers as well. i was thinking of doing something like while (inFile >> temp.balance) { inFile >> temp.balance; inFile >> temp.code; } but it doesn't really work. I also tried reading each of the individual characters. I tried turning that into an array but i couldn't figure out a good way to turn the array back into a double variable.
|
# ? May 19, 2009 06:33 |
|
Maybe you should have mentioned these details in your first post, Mr. The Riddler. That code snippet doesn't do what you want, because while (inFile >> temp.balance) attempts to read something into temp.balance, and then inFile >> temp.balance; attempts to read the next thing into temp.balance. So, you've got three attempted reads per loop instead of the two that you want. quote:in the file there are spaces between the numbers as well.
|
# ? May 19, 2009 12:08 |
|
i am having the problem now that when i use the inFile >> next, it reads the entire line of text. i get some weird number instead of 2000, which is the first number. i am thinking of trying to have it read the characters invidually and stop at the first blank space and then turn that character string into a double variable but i am not exactly sure what an efficient way for this is. I am thinking of running a do-while loop until it hits a space. it would store each character in a string and then convert the entire string into a double variable and store that in the structure.
|
# ? May 19, 2009 21:15 |
|
Stealthgerbil posted:i am having the problem now that when i use the inFile >> next, it reads the entire line of text. i get some weird number instead of 2000, which is the first number. Stop going down the path you've been going and listen to people. You just keep making things worse and not really explaining what you're even doing. code:
|
# ? May 19, 2009 21:25 |
|
Avenging Dentist posted:
You know better than to teach him this
|
# ? May 19, 2009 21:28 |
|
Otto Skorzeny posted:You know better than to teach him this I give no gently caress whatsoever about errors, especially not with I/O streams. scanf or a parser, nothing else. (Besides that, a real C++ programmer would set it to throw exceptions so you know what went wrong at the point that it went wrong, rather than at the next iteration.) EDIT: Here is simultaneously why not using exceptions with I/O streams is dangerous and also part of why I don't like I/O streams. Avenging Dentist fucked around with this message at 21:52 on May 19, 2009 |
# ? May 19, 2009 21:32 |
|
Well it works except the only problem is that it only reads the first 2 pairs of numbers from the file and doesn't read the rest. I have it set like code:
|
# ? May 19, 2009 22:07 |
|
Stealthgerbil posted:
|
# ? May 19, 2009 22:09 |
|
Otto Skorzeny posted:Let's not forget system("pause");
|
# ? May 19, 2009 22:19 |
|
Stealthgerbil posted:Well it works except the only problem is that it only reads the first 2 pairs of numbers from the file and doesn't read the rest. For everyone's sake set up an appointment with your TA or professor or something. I don't think you really understand a lot of really basic concepts in programming.
|
# ? May 19, 2009 22:48 |
|
TheSleeper posted:For everyone's sake set up an appointment with your TA or professor or something. I don't think you really understand a lot of really basic concepts in programming. Like indentation.
|
# ? May 19, 2009 23:17 |
|
|
# ? Jun 7, 2024 06:29 |
|
code:
|
# ? May 19, 2009 23:21 |