|
you can just use a valarray.
|
# ? Aug 19, 2011 04:16 |
|
|
# ? Jun 2, 2024 06:25 |
|
pseudorandom name posted:The question is, of course, was that worth the effort?
|
# ? Aug 19, 2011 07:20 |
|
shrughes posted:Edit: Also, no there's no native way. Unless the arrays are declared with a fixed size.
|
# ? Aug 19, 2011 13:05 |
|
What OS/IDE combo is best for installing libraries? (Ideally, using a package system like in Linux). Is there a general guide to installing libraries and working with .dll and .lib files? (I use Visual C++ 2010). I am confused each time I start a new project with Allegro, boost or SFML, having to set it up again even though I might have gotten it to work before.
|
# ? Aug 21, 2011 08:37 |
|
I'm pretty sure you can create your own project templates so you can just click "Create a new boost project" or whatever and have all the settings correctly configured.
|
# ? Aug 21, 2011 09:08 |
|
I can't find where that is. I have the express version of Visual Studio if that matters.
|
# ? Aug 21, 2011 09:44 |
intruder13 posted:What OS/IDE combo is best for installing libraries? (Ideally, using a package system like in Linux). Is there a general guide to installing libraries and working with .dll and .lib files? (I use Visual C++ 2010). Create some Property Sheets that covers your things, then you can just add one of those to a project to get all the settings. E.g. create one that adds the Allegro include dirs, library dirs and any other compiler settings it needs. If you do as GrumpyDoctor suggests, you can still also use property sheets (to keep the project file cleaner), but you get the advantage of having some template code files generated as well. Of course, you have to create those first
|
|
# ? Aug 21, 2011 09:47 |
|
nielsm posted:Create some Property Sheets that covers your things, then you can just add one of those to a project to get all the settings. E.g. create one that adds the Allegro include dirs, library dirs and any other compiler settings it needs. On the up side, my script does a little more for me than property sheets likely would, but on the down side, property sheets would presumably mean if I want to change something I could change it across all the shared-attribute projects rather than one at a time. (I was doing this for making many similar plugins.)
|
# ? Aug 21, 2011 16:21 |
|
code:
|
# ? Aug 21, 2011 17:02 |
Well, if your input files don't contain all alphanumerics, in whatever form, you're getting some nice infinite loops. Try indenting your code properly: code:
|
|
# ? Aug 21, 2011 17:43 |
|
Right. They're both .dat files with one string of numbers, no spaces, nothing else. No idea why the first portion works and the second doesn't. When I run my program, it doesn't exit. After printing the contents of input1.dat, it stays in limbo for a while.
Good Will Punting fucked around with this message at 18:01 on Aug 21, 2011 |
# ? Aug 21, 2011 17:48 |
|
Good Will Punting posted:Right. They're both .dat files with one string of numbers, no spaces, nothing else. No idea why the first portion works and the second doesn't. When I run my program, it doesn't exit. After printing the contents of input1.dat, it stays in limbo for a while. As nielsm implies, it looks like your code would easily accommodate skipping over newlines, spaces, whatever, if you just moved the 'get' outside of the 'if' (though then you'd get a horrible error because you only do the isalnum condition for counting, not for the actual reading - another alternative then, if you don't want to fix that problem properly, would be to put an 'else' on that 'if' where the 'else' outputs "your data file has poo poo in it" and exits. Edit: or the 'else' could just break from the loop, that way anything after the first non-digit wouldn't be read on the second pass.) The most useful and more general advice for your situation is that now would be a good time to learn to use the debugger. Probably gdb if you're operating in a Unix-like environment, or the "start debugging" option in Visual Studio, or whatever equivalent option your IDE has. That way you can step through the code and find where it's getting stuck in a loop, and see, from the variables, the reason why. roomforthetuna fucked around with this message at 18:16 on Aug 21, 2011 |
# ? Aug 21, 2011 18:13 |
|
Checked it over once more, ran the debugger. The error was weird so I Googled it and it told me to rerun VS2010 as an Admin, which I could swear I had set to default, but worth a shot right? Sure enough, the box was unchecked! Things are just dandy now, except that I'm thoroughly confused as to why this happened. Last time I had an admin issue, I set it to default to Run as Admin. It appears to have reverted back. Oh well thanks! Also, sorry for being a pest! (School has been a terrible way to learn C++ thusfar).
|
# ? Aug 21, 2011 19:26 |
|
Has school ever taught anyone C++ well? My own experiences with learning C++ in school is that it's taught as "C with classes" and topics like templates, STL (outside of cin/cout and maybe std::string), references, smart pointers, RAII, exceptions, etc. aren't even mentioned. It seems to me it would be less harmful to not teach C++ at all. I remember one professor asking me why in the world I had an overloaded assignment operator returning a self-reference in a homework assignment. He simply couldn't understand why anyone would do that.
|
# ? Aug 21, 2011 20:04 |
|
Paniolo posted:Has school ever taught anyone C++ well? My own experiences with learning C++ in school is that it's taught as "C with classes" and topics like templates, STL (outside of cin/cout and maybe std::string), references, smart pointers, RAII, exceptions, etc. aren't even mentioned. It seems to me it would be less harmful to not teach C++ at all. I learned templates, classes, the dangers of "dumb" pointers and bare arrays, intro to the stl (std::vector, std::deque and some others), and operator overloading in college. The dude even briefly talked about virtual functions though I'm pretty sure it went over everyone's heads. He'd been an actual professional software engineer, unlike most other professors I've had.
|
# ? Aug 21, 2011 20:14 |
|
This is the 2nd time I've taken a C++ course and it covers a lot of material, which is good, but it's going too quickly and we don't have enough practice implementing stuff. We've covered a shitton in lectures and notes, but as far as actually putting it into practice, we get asked to combine all this poo poo at once, in a few extremely difficult projects and two tests (which are a large chunk of our grade each) and it's overwhelming. Of what you've mentioned, we have covered overloaded operators, references, some pointers, templates, and portions of the STL (and obviously the usual class stuff). We're now doing vectors and recursion. However, while I understand it in theory, putting it all together has been a challenge for me, something things near impossible. It wouldn't be an issue if my grade was based on projects (because those help me learn so far), but they count for 0% and the tests are 100%. It's really difficult to do well on a 3 hour test when this is the first time you've worked with C++ and you're asked to use all these concepts with minimal practice beyond one example. Good Will Punting fucked around with this message at 20:40 on Aug 21, 2011 |
# ? Aug 21, 2011 20:14 |
|
Paniolo posted:Has school ever taught anyone C++ well? My own experiences with learning C++ in school is that it's taught as "C with classes" and topics like templates, STL (outside of cin/cout and maybe std::string), references, smart pointers, RAII, exceptions, etc. aren't even mentioned. It seems to me it would be less harmful to not teach C++ at all. Ironically, the one STL thing I don't make much use of is streams, the one thing that was taught at my university. But that's because I do a lot of async, overlapped and binary IO which the STL stuff (as far as I can tell) isn't great for. Edit: they did 'cover' references, it was just largely pointless (ha ha) as it was essentially "it's like a pointer that you can't change and which is more confusing." (Okay, they claimed it was less confusing so as to excuse their existence, but that's bullshit, they are way more confusing if you understand pointers.) No mention of lvalues or other actually useful uses. roomforthetuna fucked around with this message at 23:09 on Aug 21, 2011 |
# ? Aug 21, 2011 23:05 |
|
Just curious: Were you guys tested or did your courses grade you mostly based on projects? I'm stressing out because I can't figure these problems out quickly enough and I feel like it will cripple me for my test. I understand the concepts and can work everything out if I do it slowly, but god drat when I start to rush my brain gets overloaded. Sadly, that's the only way I'll succeed.
|
# ? Aug 21, 2011 23:10 |
|
roomforthetuna posted:Ironically, the one STL thing I don't make much use of is streams, the one thing that was taught at my university. But that's because I do a lot of async, overlapped and binary IO which the STL stuff (as far as I can tell) isn't great for.
|
# ? Aug 21, 2011 23:37 |
|
nielsm posted:Create some Property Sheets that covers your things, then you can just add one of those to a project to get all the settings. E.g. create one that adds the Allegro include dirs, library dirs and any other compiler settings it needs. Property sheets broke VS 2010, I think (I must have did something wrong); now it won't make new projects. I tried the reset settings but it didn't work. Also, reinstalling didn't work.
|
# ? Aug 21, 2011 23:37 |
|
Did you nuke all the VS-looking folders you could find in AppData?
|
# ? Aug 21, 2011 23:44 |
|
GrumpyDoctor posted:Did you nuke all the VS-looking folders you could find in AppData? I think I deleted a few. I will check again. Fixed. Didn't delete enough apparently. intruder13 fucked around with this message at 00:05 on Aug 22, 2011 |
# ? Aug 21, 2011 23:50 |
Hey all, I just started learning how to do stuff in C++ yesterday, and I've run into a bit of a stupid problem. First of all, you'll need my messy code. As you can see, I have a class obj, which has some fancy linking going on; I've also got a function obj_create(). Right now obj_create() is always returning 1. What I want to do is change it so that obj_create() returns a pointer to the obj that was just created...but every time I try a different way to wrestle that in the compiler just goes absolutely nuts. I appreciate any advice, and also criticism on anything I'm doing that will bite me in the future; best to catch things while I'm still learning.
|
|
# ? Aug 22, 2011 08:34 |
|
Well first of all you should actually indent stuff. This is terrible: code:
Like this: code:
Secondly, why do you even need an obj_create? Why isn't the obj constructor sufficient? Jabor fucked around with this message at 09:08 on Aug 22, 2011 |
# ? Aug 22, 2011 09:05 |
After indenting your code, consider why you are building a makeshift linked list of your objects, instead of using one of C++'s standard container templates.code:
|
|
# ? Aug 22, 2011 10:39 |
|
Manslaughter posted:Hey all, I just started learning how to do stuff in C++ yesterday, and I've run into a bit of a stupid problem. Given the complexity of what else you've already written, I'm kind of surprised you're having such an issue with your obj_create function... Does something like this not work? code:
1) Avoid variable names in classes that are single letters or weird abbreviations, things like x,y,w and h may be easier to type, but x_position, y_position, width and height are much easier to read and understand. 2) If adding something to a linked list, it's much simpler to add something to the beginning than the end: code:
http://www.sgi.com/tech/stl/List.html 4) You may want to use naming conventions to make your code easier to read. There are many different types and styles, but the general purpose of them is to add clues to the names of things so you can easily see what kind of thing they are. For example, many coders will put an "m" in front of the names of variables that are members of classes (e.g. "x_position" becomes "m_x_position") and "g" in front of globals (e.g. "head" becomes "g_head"). One common type (as used by Microsoft in their code) is Hungarian notation: http://en.wikipedia.org/wiki/Hungarian_notation Many coders (myself included) find it excessive and fiddly, and use various simplified versions, but you should be able to see the idea from the wiki page. 5) Avoid using global variables if you can, they make it harder to reuse your code and encourage you to write messy code. It's hard to explain how best to do this without writing a huge block of text, but one idea would be to make an object manager class and make things like the linked list head, object count and object creation functions members of it. This way, if for some reason you need 2 lists of objects, you can just create two instances of the manager.
|
# ? Aug 22, 2011 12:12 |
|
Plorkyeran posted:Streams aren't great for anything. There's a bunch of nifty ideas behind streams, and occasionally they seem nice when you can write one-liners like copy(istream_iterator<int>(file), istream_iterator<int>(), back_inserter(vec)); to read a list of ints from a file, but most of the time they're just a giant overcomplicated mess that solve all the wrong problems. I completely agree with you. I got deep into streams one time even going so far as to implement my own streambuffers. Later, I realized that streams are nothing but a whole lot of trouble. Printf syntax, especially when spruced up like in boost or python, is absolutely the way to go when you need to output stuff. Here's a question for boost people. I recently reverse engineered some boost binary serialized c++ objects in a hex editor and wrote some python to read in the objects. I did this for a debug tool, otherwise I wouldn't have done it at all. The python interpretation of the serialized objects is correct. Is there a better way go from boost serialized objects to python (I would rather not use Boost.Python but I have a feeling it is the more robust answer)? Does anyone have a feeling for how fragile this solution is?
|
# ? Aug 23, 2011 00:49 |
|
code:
(Bonus question: if this works, will it still work if other_foo is a smart pointer?)
|
# ? Aug 23, 2011 01:22 |
|
It'll work but it's still a bad idea.
|
# ? Aug 23, 2011 01:55 |
|
in_1 is an input file streamcode:
I should just pay one of you to be my personal C++ question answerer as I attempt (futilely) to study for my exam this weekend. There's so much little poo poo (techniques/syntax) my professor tosses into his solutions of things that he never mentions in lecture notes. And boy, Google sure is useless. This is the only useful information I've found. Good Will Punting fucked around with this message at 02:00 on Aug 23, 2011 |
# ? Aug 23, 2011 01:57 |
|
If you're confused about something, the best thing to do is actually write some code and play around with it to figure out how it works. So start by modifying the loop a little: code:
|
# ? Aug 23, 2011 02:02 |
|
Awesome, it does as I supposed. Wish I had known about this for my prior assignment, would have saved me some time instead of counting each white space then determining how many words there were from that.
|
# ? Aug 23, 2011 02:19 |
|
Paniolo posted:It'll work but it's still a bad idea. More specifically, why is initializing a child object with 'this' during the constructor a bad idea, and why does it warrant a warning? I'm thinking for something like: code:
|
# ? Aug 23, 2011 04:08 |
|
Because at that point "this" points to an object which is not yet fully constructed, so accessing it in any way is undefined behavior.
|
# ? Aug 23, 2011 04:31 |
|
Paniolo posted:Because at that point "this" points to an object which is not yet fully constructed, so accessing it in any way is undefined behavior. But if you're just initializing a pointer and you know perfectly well that you aren't going to use it for anything until after the constructor is complete, then it's really not a problem other than that "you might do something dumb later" effect. (You're not "accessing it in any way".)
|
# ? Aug 23, 2011 04:39 |
|
roomforthetuna posted:Ah, so it's a bad idea because of the possibility that at some point later you might decide that (using the same example), while initializing a LEAF, you want to do something with its siblings so you go SiblingHat=Parent->Child2.Hat (or whatever) and it all goes horribly wrong because Child2 isn't initialized yet. Yeah, that's why it's a warning not an error. It's still a bad idea though, because if you're just initializing a POD class member then why not do it in the constructor body instead, and if it's not a POD member then you're calling code with an invalid pointer as a parameter, so at any time that code could change and then you end up with REALLY hard to trace bugs. If you have a class member which needs to take a pointer to the owning class as a parameter to its constructor and you don't want to allocate it dynamically you can use boost::optional to construct it in-place later.
|
# ? Aug 23, 2011 04:56 |
|
It's also a bad idea because consider what happens when you do this:code:
|
# ? Aug 23, 2011 13:15 |
The1ManMoshPit posted:Hint: what happens isn't good, even if you move the initialize step into the body of the constructor. It's even more fun when your base class has pure virtual methods. Calling those generally causes your program to die. I fell into that trap recently.
|
|
# ? Aug 23, 2011 13:22 |
|
One of my favourite runtime errors is "Pure Virtual Function Call." Honestly, that's the better case, because your program crashes and blows up instead of just silently failing in weird and wonderful ways.
|
# ? Aug 23, 2011 13:29 |
|
|
# ? Jun 2, 2024 06:25 |
|
Good Will Punting posted:Awesome, it does as I supposed. Wish I had known about this for my prior assignment, would have saved me some time instead of counting each white space then determining how many words there were from that. I recommend you check out https://stackoverflow.com for assignment help. They have helped me hugely.
|
# ? Aug 24, 2011 00:08 |