| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13
Comments:
<0> the best idea is to refactor the code into a common function say _Init() and call that from each ctor <0> imho <1> I'm using pthread_create() to build a thread, and I need to send a (void *)arg - how can I p*** through this arg an array of 4 int elements? <2> I wouldn't call any code that can fail from a ctor... <2> You can't throw exceptions from the ctor, correct? <0> no <2> No thats not correct, or no you can't throw exceptions from the ctor? <2> I do flattening from the ctor, then have a second function Initialize() that does basic initialization (that might fail). <0> eh? <2> flattening like ***igning all my pointers to (type*)0; <2> more detailed stuff in another step... <2> I guess it depends on the complexity of the cl***... <0> exactly, the original question was about calling another ctor <0> if the ctor is likely to throw, it'll throw either way <2> But if you throw from the constructor, the objects destructor isn't called <0> and?
<2> The stuff that does succeed in the constructor would need to be undone... <0> fine...but is that relevant to the original question? <0> this is ctors 101 stuff <2> I might have missed the original question, I just saw you say to call an Init() function from the ctor <2> which if performs code that fails, it might be more difficult to undo what the ctor actually accomplished before it threw an exception <2> where it might be better to call the Init() outside the ctor <2> for better exception handling... <3> Kaervos, whay do you mean ? <3> Kaervos, if an exception is thrown during the construction of an object, all fully-constructed sub-objects are destroyed <2> The destructor isn't called if an exception is thrown from the constructor <3> Kaervos, but that's not a problem, since the object was never created <2> What if you locked a semaphore in the Init() function you call from your constructor, then an exception is thrown before the constructor is complete? <2> or opened a file <2> or allocated memory <3> Kaervos, you must unlock the semaphore, as you would do in any other function <4> If those resources are wrapped in a cl*** (and they should be, for this reason) then you're fine. <4> Google for RAII <2> Tru, Sol. <3> Kaervos, the fact that the function is a constructor doesn't make a difference in this regard <4> The pattern is cl*** Resource { ResHandle r; public: Resource() { acquire(r); } ~Resource { release(r); } }; <4> Then if every resource is so acquired (or ownership is thus transferred) exception handling, and indeed resource handling in general, is a breeze. <2> Its a case for std::auto_ptr <4> Well, std::auto_ptr is a case of the general pattern of RAII. <2> I'll go check that out <3> std::auto_ptr is suited only for heap-allocated objects <4> Kaervos: More info on the topic: http://www.relisoft.com/resource/resmain.html <4> Another good article on the same site: http://www.relisoft.com/tools/CppCritic.html <4> You should read that, Run. There are a couple of niches you could fill with your parser code. <5> http://www.noidea128.org/sourcefiles/15875.html <5> can anyone help me? <4> For future reference, "/join #c main" <6> wow... it's been a while since I've seen an array of floats :) <5> :(( <5> im so going to fail this subject <6> what are all those | in your code? <5> it's um <5> like endpoints of where the function should start and end <5> we are to make them into their own functions <7> http://www.cplusplus.com/doc/tutorial/functions.html <5> my question is, <7> Arrays are p***ed by reference by default <5> see, on the first part, what i'm thinking is that i'm going to copy the first function to void input() <7> You don't have to p*** them in and return them <5> what do you mean <5> like i can call them from another function? <7> So p*** the array and its size (10 in this case) to a function that performs the first loop <7> No, but if you p*** them in, any change you make inside the destination function is automatically communicated back to the calling function <7> http://www.cplusplus.com/doc/tutorial/functions2.html <7> Read the first section there, about reference and value parameters <5> will do <5> although what you said is still kinda aliento me :S <8> heh <7> That's because you didn't read up on functions like you were supposed to <7> Wait, this is C or C++ you're doing? <7> I don't know if arrays are p***ed by reference automagically in C, as it has no references of any sort <7> I think they are, though <8> Solamente: hello? Any chance you'll at least read a url? <7> Someone check me on that <5> c or c++? i'm not sure either <4> JBlitzen, arrays are treated the same in both.
<7> Well, look, we're not omniscient, you have to at least know what language you're supposed to be learning <4> anberlin, you're doing C <6> I think the arrays are p***ed like it's a pointer... but like casted to an array of a specific size <7> Thank you, sol <5> is there a way to distinguish? <7> Yeah, that's what I was thinking, since they aren't really references in C++ either <7> Well, anberlin, your textbook should make it pretty obvious <7> Either it's a book on C++ or a book on C <8> heh <5> we dont use a textbook <7> :| <5> it's all lecture by lecture <5> prof doesnt believe in books :S <7> Do your filenames end in .c or .cpp or .cc? <5> .c <8> heh <7> Okay, then it's C <5> what about for .cpp and .cc? <7> And, for once, I'm going to agree that your professor is an absolute moron <7> .cpp and .cc are usually C++ file extensions <7> .c is usually C <6> doesn't a .C with a big C mean like C++ too? <7> (Then there are .h and .hpp and .make extensions, but those don't mean much about which language) <7> I don't know, but he said .c, not .C <7> Is it .c or .C, anberlin? <5> .c <5> is there a difference? <8> anberlin: yes <7> Evidently <7> Anyway, I wouldn't worry about that, I'm pretty sure it's C <5> yeah this course is on data structures <4> ffs <5> ? anythin wrong <8> anberlin: he's amazed at your lack of knowledge of what you're doing, I think <4> The state of software development education is what's wrong. <4> We see its disastrous results in here every day. <5> well exactly why im asking for your help:)_ <7> http://www.cprogramming.com/tutorial/c/lesson4.html <7> anberlin ^ <5> oh alright, i'll go read up on that first. <7> At some point you'll want to start talking to #C instead of to us <5> thanks. <7> yah <5> same people right? <8> anberlin: in some cases, probably. <4> No <6> are the big internet companies arguing again? my internet is going slow and I have some fat pipes... shouldn't be slow at all <5> are you guys like, at war <4> I don't do C unless forced to do so, or paid exorbitant amounts. <5> "c is better than c++, noooo, c++ is better than c!" <8> and java's better'n them both! <8> bwahahaha <7> <5> are you guys like, at war <7> Haha <7> Not really, but they're legitimately different languages <7> The first advice I gave you out of the block was for C++, which would have screwed you up quite a bit <5> good to hear <5> wellwhat is the dif between c and c++? <7> There are a lot of differences <5> syntax? etc? <7> C++ is basically a superset of C <7> With some exceptions, C++ has the same and many more features than C <4> Used properly, C++ won't bite you in the butt like C will. <7> Reference parameters are one of the C++ exclusive features <7> So, note how long it took to come up with an example of something in C++ that can't be done the same way in C <4> C is just waiting to drop a buffer-overrun exploit or a memory leak into your application. <7> About three minutes from when we started talking to you <4> Used properly, C++ fairly eliminates problems like that. <5> wow you guys overwhelm me :( <7> Anyway, read up on that URL and see if you still have questions <3> what can be done in C and C++ ? <7> Don't be overwhelmed <5> heh
Return to
#c++ or Go to some related
logs:
#linux how to do backflips
#AllNiteCafe site:www.quotesdb.info rotards
#AllNiteCafe #linuxhelp ellezza quotes from - Bulibasha #AllNiteCafe #chatzone
|
|