|
hexadecimal posted:what is a good library for C++ that is preferably cross-platform and would allow me to make HTTP-Requests?
|
# ? Dec 2, 2008 18:12 |
|
|
# ? Apr 25, 2024 01:14 |
|
I'm really confused about classes/permissions. I'm trying to write some functions for an iterator, including begin, but I don't see how the iterator class can access/return the front node with the way this is set up. Here's SingleLL.h code:
code:
code:
Whilst farting I fucked around with this message at 22:22 on Dec 2, 2008 |
# ? Dec 2, 2008 22:20 |
|
Whilst farting I posted:I'm really confused about classes/permissions. I'm trying to write some functions for an iterator, including begin, but I don't see how the iterator class can access/return the front node with the way this is set up. I'm not sure what you're confused about??? code:
|
# ? Dec 2, 2008 22:23 |
|
Whilst farting I posted:I'm really confused about classes/permissions. I'm trying to write some functions for an iterator, including begin, but I don't see how the iterator class can access/return the front node with the way this is set up.
|
# ? Dec 2, 2008 22:37 |
|
Avenging Dentist posted:I'm not sure what you're confused about??? When I do that I get a really long error whenever I call it, but here's the most relevant part quote:68 C:\SingleLL.cpp no match for call to `(SingleLL<std::vector<std::string, std::allocator<std::string> > >::iterator) (SingleLL<std::vector<std::string, std::allocator<std::string> > >::Node*&)'
|
# ? Dec 2, 2008 22:51 |
|
Whilst farting I posted:When I do that I get a really long error whenever I call it, but here's the most relevant part That's probably because you didn't write a constructor to your iterator. Just take a Node* and copy it to pointer in the iterator object.
|
# ? Dec 2, 2008 22:55 |
|
code:
|
# ? Dec 2, 2008 23:18 |
|
Whilst farting I posted:
This code has a memory leak (you allocate a new node for frontNode and then reassign the pointer without deleting the original node), and you don't give the Node pointer to the iterator. Here is a minimal change to the function to make it work, but it is by no means the advised solution: code:
|
# ? Dec 2, 2008 23:47 |
|
I knew it had something to do with how it was being returned and totally missed the whole pointer thing. I've been trying this on a few different compilers to try and pinpoint the problem and some have been picky about the declarations, but the most specific one worked across them all so I had been using that. Thanks for clarifying this!
|
# ? Dec 3, 2008 00:03 |
|
Once you get this working, you may want to look into Boost's Iterator Facade. It's basically a template that makes it much, much easier to write conforming iterator implementations (i.e. to make sure it does all the obscure stuff that iterators are required to do).
|
# ? Dec 3, 2008 00:34 |
|
Avenging Dentist posted:Once you get this working, you may want to look into Boost's Iterator Facade. It's basically a template that makes it much, much easier to write conforming iterator implementations (i.e. to make sure it does all the obscure stuff that iterators are required to do). Somewhat improperly placed are also the Iterator Helpers of Boost.Operators which may be a simpler option.
|
# ? Dec 3, 2008 02:15 |
|
Whilst Farting, I just wanted to be clear, this is for a school project right? You're not writing production code doing this are you?
|
# ? Dec 3, 2008 13:58 |
|
Dren posted:Whilst Farting, I just wanted to be clear, this is for a school project right? You're not writing production code doing this are you? I really hope nobody is rolling their own linked list for production code. This looks like a pretty standard data structures class assignment.
|
# ? Dec 3, 2008 14:54 |
|
I have to implement an ActiveX container. Not a control - I have the control. A container. Oh, God, shoot me now. Question 1: Anyone know where to find good docs on doing this? I can't find anything reasonable anywhere. Question 2: I found a "sample" on MSDN, here. But it's not the actual sample, it's just a description of the sample and how to use it. I don't seem to have this sample installed anywhere with my copy of Visual Studio. Anyone know where to download the actual code for this?
|
# ? Dec 3, 2008 18:31 |
|
Here's one for you all, about C++ and callbacks. In the current implementation of my code, my CDataContainer class has a set of three ordinary C function pointers that are set on construction and used throughout the class. The problem with these is, it's been decided that these need to be able to point to member functions INSTEAD of static/global functions. The solution I came up with first was interfaces, then I remembered that C++ doesn't have interfaces. It DOES, however, have multiple inheritance. So I figure I could fake interfacing by writing a class like this: code:
code:
|
# ? Dec 3, 2008 19:57 |
|
Ledneh posted:I know multiple inheritance is omgevil Don't forget the virtuals: code:
|
# ? Dec 3, 2008 20:26 |
|
Ledneh posted:I know multiple inheritance is omgevil, but the only alternative I could think of is having classes use a static wrapper and passing objects along via void pointers which strikes me as even worse. Is this multiple inheritance a reasonable solution? Or is there a better one I could be working with as far as allowing callbacks to member functions? If you just need member functions you can use member function pointers. If you need one single object to be able to work with function pointers, member function pointers, more general function objects, etc. you should consider using TR1's function template or Boost.Function.
|
# ? Dec 3, 2008 20:27 |
|
Mustach posted:I'm going to preempt Avenging Dentist and point you toward Boost.Function and Boost.Bind You beat out both AD and me to a boost link, that deserves an award.
|
# ? Dec 3, 2008 20:28 |
|
Thanks for the link to boost::function, but I'm getting the impression from the guys upstairs (I need to check) that there could be many different classes that need to be able to support these callbacks, and I won't know in advance what classes these are, at least not yet (security clearance! ). Even if I DID know in advance, the fact that there could be more than one class in need of calling back I think means I need to use this fake-interface. (edit: I could be wrong, since I know literally dick about what bind is capable of) Thanks for the suggestions, I'll look into them some more after lunch. And yeah, I forgot the virtuals 'cause I'm sort of a dullard when I'm not actually in front of a machine with a compiler Ciaphas fucked around with this message at 21:00 on Dec 3, 2008 |
# ? Dec 3, 2008 20:53 |
|
Man, I was going to post the boost link before all of you, but I figured the guy wanted something more java-ish.
|
# ? Dec 3, 2008 20:54 |
|
You say you currently use composition (your classes HAVE three C function pointers). Well, if you use boost::function, you will still be using composition. Any class that wants callbacks will simply HAVE boost function objects. And the best part is boost function objects can transparently encapsulate whatever you want. C functions. Functors. Static member functions. Instance member functions. Any or all of the above in combination. Even better, with together with boost::bind you can employ partial function application on more general callables to wrap them with individual per-callback-state before you store them as callbacks, if you need to. Guaranteed, boost is absolutely more flexible and more portable and more complete than any possible wheel you decide to re-invent on your own. BigRedDot fucked around with this message at 00:32 on Dec 4, 2008 |
# ? Dec 4, 2008 00:28 |
|
BigRedDot posted:Guaranteed, boost is absolutely more flexible and portable and co,plete than anything possible thing you roll yourself. Especially since Boost.Bind and Boost.Function are both a part of TR1.
|
# ? Dec 4, 2008 00:29 |
|
Okay, consider me sold well enough. I did some reading up, and frankly I missed the boat earlier on how bind and function interrelate. I see it a little better now. Still gonna take some working out I think, though, mostly to make sure I'm not running up against the rest of the group's wishes. Thanks!
|
# ? Dec 4, 2008 00:34 |
|
That Turkey Story posted:You beat out both AD and me to a boost link, that deserves an award.
|
# ? Dec 4, 2008 01:36 |
|
MarsMattel posted:How about making a series of tests which cover a range of problems of varying difficulty? Just say ten or so examples like, "can you find the error in this piece of code?" I think questions like that tend to be a bit too easy, for example I'm a freshman CS student and I immediately see the problem there :/
|
# ? Dec 4, 2008 06:09 |
|
king_kilr posted:I think questions like that tend to be a bit too easy, for example I'm a freshman CS student and I immediately see the problem there :/ You'd be surprised who shows up at interviews saying they can program.
|
# ? Dec 4, 2008 07:21 |
|
Ugg boots posted:You'd be surprised who shows up at interviews saying they can program. I've seen CS grads show up to interviews lacking the ability to describe what a hash table is and how it works.
|
# ? Dec 4, 2008 08:57 |
|
Mikey-San posted:I've seen CS grads show up to interviews lacking the ability to describe what a hash table is and how it works. I've seen interviewees with CS masters unable to write a for loop.
|
# ? Dec 4, 2008 09:20 |
|
Zombywuf posted:I've seen interviewees with CS masters unable to write a for loop. How can something like that be possible?
|
# ? Dec 4, 2008 09:26 |
|
hexadecimal posted:How can something like that be possible? hexadecimal posted:check out this #define I have found somewhere and have been using for a while. It makes iterating through STL containers a lot easier. Hmm...
|
# ? Dec 4, 2008 09:50 |
|
^^^ ahahahaZombywuf posted:I've seen interviewees with CS masters unable to write a for loop. CS degrees, now available in every box of Cracker Jack(r) popcorn snacks!
|
# ? Dec 4, 2008 09:51 |
|
hexadecimal posted:How can something like that be possible? A lot of the time you don't need a Bachelor's in CS to pursue a Master's in CS, for example a lot of schools will let you hop right into a Master's in CS program with a Physics or Math degree. Though you might need to take classes to satisfy prerequisites for the classes in the graduate school, you'll probably avoid taking any introductory programming classes, and often the Graduate CS classes are weighted more toward theory than programming, so you might not do much (if any) programming in Graduate school.
|
# ? Dec 4, 2008 09:53 |
|
king_kilr posted:I think questions like that tend to be a bit too easy, for example I'm a freshman CS student and I immediately see the problem there :/ Same, but I've run into people in my 200-level software systems course who can't figure out the problem when they're trying to compile code with a mismatched parenthesis.
|
# ? Dec 4, 2008 13:36 |
|
So regarding boost::bind and boost::function again. Take the following example I borrowed from another programming forum:pre:#include <boost/bind.hpp> #include <boost/function.hpp> #include <iostream> class container { public: boost::function<void()> callback; }; class foo { public: void doStuff() {std::cout << "Hello World!\n";} }; int main() { container c; foo f; c.callback = boost::bind(&foo::doStuff, &f); c.callback(); }
|
# ? Dec 4, 2008 17:06 |
|
Does not compile on gcc without the ampersand.
|
# ? Dec 4, 2008 17:35 |
|
Ledneh posted:Take that bolded line. If I take the ampersand out of before foo::doStuff, the example seems to work exactly the same as if I left it in. But are there any side effects I should know about? You always form member function pointers by doing &Type::member_function, otherwise your code is non-standard and will not compile on a compliant compiler. This is true even when in the scope of the class. With non-member functions you can leave off the & and still be standard.
|
# ? Dec 4, 2008 17:48 |
|
Another case of CC screwing with me, then.
|
# ? Dec 4, 2008 17:48 |
|
Okay, there's two different ways I can think of of going about this. Pretend when you read these that I bothered checking for null errors and such; my internet computer and compiler computer are not one and the same, or even near each other, so I'm kind of playing by ear. This first way doesn't require the caller (read: the rest of the team) to use or even know about boost::bind or boost::function, which is good for them, but makes me have to use a void*, and looks a little odd to use. my code code:
code:
my code code:
code:
(ed) Also, thanks for your patience with me, I know these are sort of basic questions but I'm new to the practical world of programming. The theoretical world of college programming was easier Ciaphas fucked around with this message at 19:35 on Dec 4, 2008 |
# ? Dec 4, 2008 19:32 |
|
Take this function:code:
|
# ? Dec 4, 2008 20:01 |
|
|
# ? Apr 25, 2024 01:14 |
|
T sum = T(); should work in all cases I can think of.
|
# ? Dec 4, 2008 20:04 |