|
Nippashish posted:Nippashish talks event handling I may have had a stroke of insight on my way home from class the other day, so tomorrow and over the weekend I'm going to try testing a few things and implementing some ideas. I may have nailed something down, but then again, maybe not. I'll sit down tomorrow and piece through all the different code I've collected so far and see if I'm right or not. Your example was incredibly helpful, as well. Is there a good website(s) that discuss maps, function callbacks and templates? I usually visit https://www.cplusplus.com to get me started, and then browse around if that doesn't answer my questions. https://www.newty.de seems like a good place for function points and callbacks, but what about the others?
|
# ? Nov 21, 2008 03:58 |
|
|
# ? Jun 8, 2024 17:53 |
|
Just FYI, cplusplus.com is one of the worst C++ sites out there.
|
# ? Nov 21, 2008 03:59 |
|
User0015 posted:I may have had a stroke of insight on my way home from class the other day, so tomorrow and over the weekend I'm going to try testing a few things and implementing some ideas. I may have nailed something down, but then again, maybe not. I'll sit down tomorrow and piece through all the different code I've collected so far and see if I'm right or not. Your example was incredibly helpful, as well. For the stl I usually use http://www.cppreference.com/ for a quick reference and http://www2.roguewave.com/support/docs/sourcepro/edition9/html/stdlibref/index.html when I need an answer in detail. As for learning templates, I learned to use them by reading the http://www.boost.org/ documentation; however, this is probably not the easiest way to go about it. Boost has pretty good documentation for most of their libraries, but they also assume you know what you're doing with templates. If you're up for it, try looking at boost::bind for a really excellent and more general version of what MemberFunctionHandler from your last post is trying to be. I'd point you to some more introductory reading, but I'm afraid I don't know any good ones. Nippashish fucked around with this message at 05:56 on Nov 21, 2008 |
# ? Nov 21, 2008 05:52 |
|
Avenging Dentist posted:Just FYI, cplusplus.com is one of the worst C++ sites out there. What would you recommend instead.
|
# ? Nov 21, 2008 07:50 |
|
User0015 posted:What would you recommend instead. Any/all of the links in my OP
|
# ? Nov 21, 2008 07:55 |
|
Avenging Dentist posted:Any/all of the links in my OP I'll take a look. I honestly assumed the links you put up were for experts and professionals, since a lot of discussion and information in the entire forum is a little beyond college level. At least, that's what it looks like at first glance.
|
# ? Nov 21, 2008 08:00 |
|
Nah, the pros just bust out their copy of ISO/IEC 14882:2003. Legend has it that That Turkey Story learned from the ISO standard.
|
# ? Nov 21, 2008 08:09 |
Why is mmap always returning -1:code:
EDIT: Added MODE data. Still no go. Jo fucked around with this message at 08:41 on Nov 21, 2008 |
|
# ? Nov 21, 2008 08:28 |
|
Jo posted:Why is mmap always returning -1: Perhaps you could print out the actual error? errno exists for a reason, you know.
|
# ? Nov 21, 2008 08:54 |
ShoulderDaemon posted:Perhaps you could print out the actual error? errno exists for a reason, you know. Ehr, yes. Right. It's errno 9. Bad file descriptor. EDIT: It's late, I'm probably making a stupid error opening the file or something. Thank you for your response at this ungodly hour, ShoulderDaemon. server1.rpc has permissions hosed up. Jo fucked around with this message at 09:09 on Nov 21, 2008 |
|
# ? Nov 21, 2008 09:00 |
|
Jo posted:Ehr, yes. Right. It's errno 9. It's probably because you have a bad file descriptor. I'm betting your open call is failing and returning -1. You should check that.
|
# ? Nov 21, 2008 09:06 |
|
Jo posted:Ehr, yes. Right. It's errno 9. Ever tried out strace?
|
# ? Nov 21, 2008 09:32 |
|
Avenging Dentist posted:Nah, the pros just bust out their copy of ISO/IEC 14882:2003. Legend has it that That Turkey Story learned from the ISO standard. This is more fact than legend
|
# ? Nov 21, 2008 15:46 |
Vanadium posted:Ever tried out strace? Never heard of it before. Looks really neat, but it's not installed on the dev server and I don't have administrative privileges.
|
|
# ? Nov 22, 2008 21:17 |
|
how can i make a function with arbitrary number of arguments, like printf? Also how can i create function pointers to such functions? Beside casting them from void *
|
# ? Nov 23, 2008 07:01 |
|
Maxcraft posted:how can i make a function with arbitrary number of arguments, like printf? These are called "variadic" functions. Here are some guides on implementing them: http://www.gnu.org/software/libtool/manual/libc/How-Variadic.html http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=138 http://www.inquiry.com/techtips/cpp_pro/10min/2001/feb/10min0201-3.asp Pointers to variadic functions are declared with the same syntax as any other function pointer.
|
# ? Nov 23, 2008 07:08 |
|
Maxcraft posted:how can i make a function with arbitrary number of arguments, like printf? Please don't do this in C++ unless you have a really good reason.
|
# ? Nov 23, 2008 07:13 |
|
How do you pack files into an executable? I barely know how to do this using resource files with visual studio, but I'm looking for a more standard and platform-independent way to do this, if there is one. What is the best way to manage a large set of constants that are going to be used throughout a program like an ini file? I want to be able to look up and modify values by a string name (like reading from a file or console) but also be able to very quickly access these values (ideally without looking them up each time I need them) throughout the program. This seems like a problem that has probably been solved thousands of times in C++ and I'd probably do a pretty awful job trying to come up with a solution on my own. How do you work with callback functions that need to communicate without using global variables? Right now I'm doing some programming with GLUT and I really have no idea how to get things like a key callback and a timer callback to talk to each other without making every little variable I need a global. Actually, it just occurred to me I could make each callback a member of a class and talk through member variables, but what if I wanted to do this in C? I'm just curious if there are better ways to design around this problem.
|
# ? Nov 23, 2008 08:53 |
|
Contero posted:How do you pack files into an executable? I barely know how to do this using resource files with visual studio, but I'm looking for a more standard and platform-independent way to do this, if there is one. There is no platform-independent way because it depends on the executable format. Windows uses PE, which is different from ELF in Linux. Contero posted:What is the best way to manage a large set of constants that are going to be used throughout a program like an ini file? Boost.ProgramOptions, deserialize to a struct. Contero posted:How do you work with callback functions that need to communicate without using global variables? Right now I'm doing some programming with GLUT and I really have no idea how to get things like a key callback and a timer callback to talk to each other without making every little variable I need a global. Actually, it just occurred to me I could make each callback a member of a class and talk through member variables, but what if I wanted to do this in C? I'm just curious if there are better ways to design around this problem. That's not gonna work in GLUT. You can't use member functions as function pointers (at least not in the way you want). Real mens' APIs that use callbacks let you supply a function object, and then you can do whatever you want, especially if you use the Boost/TR1 bind function.
|
# ? Nov 23, 2008 09:08 |
|
^^^^^^^^^^^^^^^^^^^^^ you can use a big char array in .h file. I did this to include bitmap files in my glut project. I had about 2mb .h file with all my textures as big char arrays. It made one large executable but it needed no other files to run other than itself. you can use a map for your second problem. you can have something like map<string,int> and it would map some string to some integer value. you can have any data type as key or value. example: code:
code:
quote:That's not gonna work in GLUT. You can't use member functions as function pointers (at least not in the way you want). Real mens' APIs that use callbacks let you supply a function object, and then you can do whatever you want, especially if you use the Boost/TR1 bind function. To pass functions that are member methods of class, i think you have to make them static, otherwise you cannot have function pointers to them.
|
# ? Nov 23, 2008 09:14 |
|
hexadecimal posted:you can use a map for your second problem. you can have something like map<string,int> and it would map some string to some integer value. you can have any data type as key or value. That's not going to help with serializing/deserializing the data to/from a file or reading from the command-line, which is what he was asking about, and why I suggested Boost.ProgramOptions. By way of example, I used Boost.ProgramOptions for one of my projects recently to read in a config file in INI format and it took me 20 lines of code, excluding declarations. Also, keep in mind that the asymptotic complexity of an algorithm isn't the only measure of its speed, and depending on the amount of data, it may be easiest just to make a struct with members for every option.
|
# ? Nov 23, 2008 09:28 |
|
Okay, I'm doing an assignment for my C++ class. The assignment is to make a program that can encode plain text into morse code, and decode morse code into plain text. I got the first part down. It's the second part that's killing me here. I need a way to input the initial string for morse code, then go through that string, and assign each group of characters to their own position in a string array, delimited by a blank. So, if the input was: code:
Does anyone know of a way to do this? Short of falling back on going one character by one, this has me stumped. Cosmopolitan fucked around with this message at 12:28 on Nov 23, 2008 |
# ? Nov 23, 2008 12:25 |
|
Anunnaki posted:I was thinking about doing something like actually using getline on the input string's variable, but I don't think that would work, since I don't think a variable counts as an input stream. You can use an std::istringstream to wrap your string into an input stream, then you can use >> to get whitespace-delimited tokens into std::strings. Also you could just keep calling std::string::find on the input string to find the next space, and then use std::string::substr to extract the token manually.
|
# ? Nov 23, 2008 13:57 |
|
Contero posted:How do you pack files into an executable? I barely know how to do this using resource files with visual studio, but I'm looking for a more standard and platform-independent way to do this, if there is one. Qt has its own resource compiler which is much more convenient that Microsoft's, and works on Windows, Mac and Linux. You need to use Qt's QFile class to open the files you embed, but you can get that class by linking only to the QtCore module which is pretty small and ignore the rest of the GUI toolkit. (But if you're making a cross-platform app, Qt's a good choice to do the UI in anyway.) quote:How do you work with callback functions that need to communicate without using global variables? Right now I'm doing some programming with GLUT and I really have no idea how to get things like a key callback and a timer callback to talk to each other without making every little variable I need a global. Actually, it just occurred to me I could make each callback a member of a class and talk through member variables, but what if I wanted to do this in C? I'm just curious if there are better ways to design around this problem. In most C systems I've seen a callback function has a void * parameter called "userdata" or something that you can pass anything you want to. So you'd pass it a pointer to a struct which has all the data members you want to communicate with. I just looked up glutTimerFunc and apparently it only lets you pass a single int, so you'd need to do something like make a global array of structs (pointed at through void pointers so you can have a different struct at each position) and use the int as an index into it. A bit ugly, but a single global array is better than a bunch of unrelated global data.
|
# ? Nov 23, 2008 18:41 |
|
Anunnaki posted:Okay, I'm doing an assignment for my C++ class. The assignment is to make a program that can encode plain text into morse code, and decode morse code into plain text. I got the first part down. It's the second part that's killing me here. I made this little C++ function to take a string and string delimeter, and return a vector of strings that are broken around that delimeter. Also in getline you can use getline( cin, string_name, ' ' ); to make it break with spaces and not with new lines. here is the code for my function, maybe it will help: code:
hexadecimal fucked around with this message at 19:14 on Nov 23, 2008 |
# ? Nov 23, 2008 19:11 |
|
I had a friend ask for help with an array program he is working on in C. I looked at the source but cannot for the life of me find why the compiler (Dev-C++ in my case) is throwing this one error. The program is to take the int array and pass it to various functions for processing. It is "menu" driven using a while loop and a switch statement for control. code:
line 41: syntax error before "int" (which is located inside the switch statement in the above code) I have some experience with C++, but this is puzzling me. My first thoughts were improper pass by reference or something... maybe even scope issues since there are functions outside of main(). I commented out the offending line and it compiled fine. Any thoughts?
|
# ? Nov 23, 2008 21:13 |
|
you declare array A when you pass it to that function. just pass A instead of int A[]. Also declare int A[] outside of main() where you do forward declaration of those functions. This way it would be visible in menu code:
hexadecimal fucked around with this message at 21:23 on Nov 23, 2008 |
# ? Nov 23, 2008 21:17 |
|
Most excellent! Thank you hex, I see where it went wrong now.
|
# ? Nov 23, 2008 21:24 |
|
Anunnaki posted:I need a way to use something like getline to search the input, and every time there's a space, grab the preceding characters and put them in their own position in a string array string s; cin >> s; It stops when it reaches whitespace. I have no idea why people are writing anything more complicated?
|
# ? Nov 24, 2008 01:28 |
|
crazypenguin posted:string s; Because I need it to look at the whole string, and not just up to the first blank (which would only be the equivalent of one plain-text character). Plus, if I'm not mistaken, it will corrupt the I/O buffer. Anyway, I've been at this for hours, and I just can't figure it out. It's probably just because we haven't learned about vectors yet, so I can't see what I'm doing wrong, but this is driving me up a wall. Here's the portion of my code that's supposed to decode morse code into plain text: code:
|
# ? Nov 24, 2008 02:12 |
|
Anunnaki posted:Because I need it to look at the whole string, and not just up to the first blank (which would only be the equivalent of one plain-text character). Plus, if I'm not mistaken, it will corrupt the I/O buffer. What in god's name are you talking about
|
# ? Nov 24, 2008 02:24 |
|
Avenging Dentist posted:What in god's name are you talking about cin stops after the first whitespace. I'm entering a whole string of morse code, each character separated by a space.
|
# ? Nov 24, 2008 02:29 |
|
code:
|
# ? Nov 24, 2008 02:30 |
|
Anunnaki posted:cin stops after the first whitespace. I'm entering a whole string of morse code, each character separated by a space. Based on your code, you clearly know what loops are; why wouldn't you use them?
|
# ? Nov 24, 2008 02:39 |
|
Avenging Dentist posted:Based on your code, you clearly know what loops are; why wouldn't you use them? I'm sure if I knew what you were talking about, I wouldn't be here asking for help.
|
# ? Nov 24, 2008 03:33 |
|
Anunnaki posted:I'm sure if I knew what you were talking about, I wouldn't be here asking for help. just use the code i wrote up duder. you will have to #include <map> and use the function to split strings. But it should work fine otherwise. Using maps would probably make converting from normal text to morse code a lot easier. One thing i forgot to mention is that you probably want to know how to check if certain value is mapped or not? that is if something that user entered is really a morse code code? you can use this: code:
code:
hexadecimal fucked around with this message at 03:44 on Nov 24, 2008 |
# ? Nov 24, 2008 03:39 |
|
Anunnaki posted:cin stops after the first whitespace. I'm entering a whole string of morse code, each character separated by a space. I'm more curious about the "corrupt the I/O buffer" part.
|
# ? Nov 24, 2008 03:43 |
|
hexadecimal posted:just use the code i wrote up duder. Yeah but your code is awful. floWenoL posted:I'm more curious about the "corrupt the I/O buffer" part. Yeah, that's what I was saying "what" about
|
# ? Nov 24, 2008 03:43 |
|
hexadecimal posted:just use the code i wrote up duder. you will have to #include <map> and use the function to split strings. But it should work fine otherwise. Using maps would probably make converting from normal text to morse code a lot easier. I tried, but it doesn't compile. I don't get how you're defining that vector<string>. Edit: Also, I don't know what a map is. I can't find it in my textbook, and the page for it on cplusplus.com is confusing. floWenoL posted:I'm more curious about the "corrupt the I/O buffer" part. Cosmopolitan fucked around with this message at 03:57 on Nov 24, 2008 |
# ? Nov 24, 2008 03:51 |
|
|
# ? Jun 8, 2024 17:53 |
|
Anunnaki posted:I tried, but it doesn't compile. I don't get how you're defining that vector<string>. Edit: Also, I don't know what a map is. I can't find it in my textbook, and the page for it on cplusplus.com is confusing. http://www.cppreference.com/wiki/stl/map/start here is one for the maps. Its basically a way to have an associative array. Associative array is an array where index can be anything not just numbers from 0...size of array. Think of it like a dictionary. You can map a string word to its definition that can also be a string. for vector just make sure you #include <vector> and make sure you either do using namespace std; or using std::vector; in the splitString function i use std:: in front of it and string to make sure that function works without having to do using std::vector; or using namespace std; before EDIT: and oh yea, #include <map> for maps, of course. hexadecimal fucked around with this message at 04:07 on Nov 24, 2008 |
# ? Nov 24, 2008 04:04 |