|
I have a question about inheritance in C++. The C++ FAQ says that inheritance is not for code re-use, but rather for polymorphism and other related features. This seems to conflict with the old "Shape" example (class Shape contains a Position method and related variables, Circle and Rectangle inherit from Shape and inherit this method and data, so more code re-use). Is using inheritance for this reason wrong? If so, why? What am I missing here?
|
# ? Mar 5, 2008 16:14 |
|
|
# ? May 6, 2024 03:40 |
|
WalletBeef posted:What is the best, free, windows C++ compiler? As far as I know, your choices are basically Visual Studio Express or MinGW. Express has the advantage that it's closer to the full, for-pay version of Visual Studio, which is what all Windows software ever is built with, but the disadvantage that it's missing some things and lots of documentation or other software you might want to work with assumes you have those things. MinGW is the Windows port of gcc, the compiler used on every OS except Windows, which is completely free itself, so documentation about gcc will usually transfer right over.
|
# ? Mar 5, 2008 16:15 |
|
Visuacl C++ 2008 Express Edition It has the added benefit of being able to create nice GUI's.
|
# ? Mar 5, 2008 16:15 |
|
ColdPie posted:I have a question about inheritance in C++. The C++ FAQ says that inheritance is not for code re-use, but rather for polymorphism and other related features. This seems to conflict with the old "Shape" example (class Shape contains a Position method and related variables, Circle and Rectangle inherit from Shape and inherit this method and data, so more code re-use). Is using inheritance for this reason wrong? If so, why? What am I missing here? The point is that Position and related variables logically belong to all the various subclasses of Shape. If you had a method that happened to be coded very similarly for Circles and Rectangles, but not for Squares, you wouldn't want to add a base class that both Circle and Rectangle inherit from but Square doesn't just to hold this method, because that would make no sense. You also wouldn't put the Circle and Rectangle version in the base class and then have Square override it, because the Circle and Rectangle version doesn't apply to all Shapes so it has no reason being in the base class. (You also wouldn't just duplicate the code in the two classes - make a standalone friend function that's called from both, or something.)
|
# ? Mar 5, 2008 16:24 |
|
MEAT TREAT posted:Visuacl C++ 2008 Express Edition Uh, Visual C++ doesn't have a monopoly on nice GUI's. I'm not even sure what you mean by that - a compiler that couldn't be used to compile a GUI is pretty useless.
|
# ? Mar 5, 2008 16:25 |
|
JoeNotCharles posted:The point is that Position and related variables logically belong to all the various subclasses of Shape. If you had a method that happened to be coded very similarly for Circles and Rectangles, but not for Squares, you wouldn't want to add a base class that both Circle and Rectangle inherit from but Square doesn't just to hold this method, because that would make no sense. You also wouldn't put the Circle and Rectangle version in the base class and then have Square override it, because the Circle and Rectangle version doesn't apply to all Shapes so it has no reason being in the base class. (You also wouldn't just duplicate the code in the two classes - make a standalone friend function that's called from both, or something.) Oh, I get you. That makes sense. Thank you.
|
# ? Mar 5, 2008 16:28 |
|
JoeNotCharles posted:Uh, Visual C++ doesn't have a monopoly on nice GUI's. I'm not even sure what you mean by that - a compiler that couldn't be used to compile a GUI is pretty useless. It's also an IDE that lets you create windows forms and see what they are going to look like. edit: IDE != Compiler, but it still a benefit you get with Visual Studio. Janitor Prime fucked around with this message at 19:26 on Mar 5, 2008 |
# ? Mar 5, 2008 19:10 |
|
I considered making a separate post for this, but it'd probably be better here. Here's the short version: I need a ton of help compiling this for a research group I'm involved with. I'm prepared to pay for help, as I have no idea what I'm doing, and very little time to do it in. Long version: I started working for a research group doing bioinformatics stuff. The work is cool, but since I'm a CS major, I've gotten pigeonholed into maintaining the above project on top of all my other responsibilities. I said I could play around with it, but I really wanted to work on other stuff. Unfortunately, the machine which had a compiled version died and we are in urgent need of getting the code up and running on other machines. It's midterm week(s), and I'm swamped to hell. The only build instructions left "just use KDevelop 2.3" despite it being built on top of autotools. So, in short, I need this, and I need it fast. I don't need an elegant fix -- although one would be nice -- just something that works. I have never worked with C++ or autotools, and I'm getting super frustrated. I have no idea how easy/difficult this is, but when I have more time, I want to make it much easier to compile (like, ./configure && make && make install easy). If it's a larger problem than I currently think, I'm more than willing to pay a bit, considering the urgency of this. Please help . defmacro fucked around with this message at 20:47 on Mar 5, 2008 |
# ? Mar 5, 2008 19:57 |
|
GT_Onizuka posted:I have never worked with C++ or autotools, and I'm getting super frustrated. I have no idea how easy/difficult this is, but when I have more time, I want to make it much easier to compile (like, ./configure && make && make install easy). If it's a larger problem than I currently think, I'm more than willing to pay a bit, considering the urgency of this. It's almost that simple already. Install automake and autoconf, then: code:
|
# ? Mar 6, 2008 03:52 |
|
JoeNotCharles posted:It's almost that simple already. Install automake and autoconf, then: Oh wow, that certainly helped out quite a bit. I'm getting some errors, but they seemed to be related to the libraries. Considering how old things are, I suppose I shouldn't be too surprised. Thanks again, I'm almost on my way! EDIT: I know this is a long shot, as it's some random library, but I figure it's worth a shot. Here's the error I get: code:
defmacro fucked around with this message at 07:13 on Mar 6, 2008 |
# ? Mar 6, 2008 05:18 |
|
I'm fairly new to C++ and I'm wondering what the regular expression library du jour is. For a project in my CS class, we have to parse fairly large files (right now I'm going line-by-line with the regular expression "^([A-Za-z0-9]+),([A-Za-z0-9]*),([A-Za-z0-9]*),(s?f?|f?s?);$"), and I'm using regex.h which is unfortunately incredibly slow. I see that there's Boost.Regex, but we have to hand in our source code at the end of the project and I'm not sure that it's feasible to merge the Boost shared library stuff into my makefiles just for this. Should I just parse it by hand? Is there a better solution? I'm used to being able to just go to the Java or Python docs and glance at the syntax in the manual but I'm having kindof a hard time doing that with C++.
|
# ? Mar 6, 2008 18:40 |
|
GT_Onizuka posted:Oh wow, that certainly helped out quite a bit. I'm getting some errors, but they seemed to be related to the libraries. Considering how old things are, I suppose I shouldn't be too surprised. Thanks again, I'm almost on my way! It looks like either the headers are out of date with the libraries you're linking in (unlikely), or you're not linking in the library correctly.
|
# ? Mar 6, 2008 22:03 |
|
illamint posted:I see that there's Boost.Regex, but we have to hand in our source code at the end of the project and I'm not sure that it's feasible to merge the Boost shared library stuff into my makefiles just for this. Should I just parse it by hand? Is there a better solution? I'm used to being able to just go to the Java or Python docs and glance at the syntax in the manual but I'm having kindof a hard time doing that with C++. There's also regex in TR1 that's based off of Boost.Regex and is probably supported by your compiler's standard library already.
|
# ? Mar 6, 2008 22:11 |
|
illamint posted:the regular expression "^([A-Za-z0-9]+),([A-Za-z0-9]*),([A-Za-z0-9]*),(s?f?|f?s?);$"), Do all the lines in the file match this? If so, a regex is overkill. vv also overkill. Writing a DFA for this would be very easy. Scaevolus fucked around with this message at 02:19 on Mar 7, 2008 |
# ? Mar 6, 2008 23:43 |
|
illamint posted:I'm fairly new to C++ and I'm wondering what the regular expression library du jour is. For a project in my CS class, we have to parse fairly large files (right now I'm going line-by-line with the regular expression "^([A-Za-z0-9]+),([A-Za-z0-9]*),([A-Za-z0-9]*),(s?f?|f?s?);$"), and I'm using regex.h which is unfortunately incredibly slow. I see that there's Boost.Regex, but we have to hand in our source code at the end of the project and I'm not sure that it's feasible to merge the Boost shared library stuff into my makefiles just for this. Should I just parse it by hand? Is there a better solution? I'm used to being able to just go to the Java or Python docs and glance at the syntax in the manual but I'm having kindof a hard time doing that with C++. use lex DFAs are harder to implement in C++ than writing a lexer that can do the same thing. Lexer outputs DFA anyway. Just define your reg expression and associate a rule for when lexer finds it (that is what C++ code to execute), and voila, you are done. Entheogen fucked around with this message at 14:53 on Mar 7, 2008 |
# ? Mar 7, 2008 00:37 |
|
Scaevolus posted:Do all the lines in the file match this? If so, a regex is overkill.
|
# ? Mar 7, 2008 05:38 |
|
I'm not entirely sure if this is the right place to post this but I'll give it a shot. Basically creating a c# web application. After they submit information into the database, a email is needed to be dispatch displaying the contents that was just added. Anyway I get this error and its anoying me Format of the initialization string does not conform to specification starting at index 0. It shows at the connection string. code:
|
# ? Mar 7, 2008 12:41 |
|
Eararaldor posted:I'm not entirely sure if this is the right place to post this From the list of megathreads, you want the .Net (C#, VB.NET [VB 2003, 2005, and 2008]) Questions Megathread megathread.
|
# ? Mar 7, 2008 15:17 |
|
csammis posted:From the list of megathreads, you want the .Net (C#, VB.NET [VB 2003, 2005, and 2008]) Questions Megathread megathread. Ah thanks. BTW problem solved anyway.
|
# ? Mar 7, 2008 16:38 |
|
I suspect that I'm entirely retarded for this problem, but: I am finding myself unable to create a bitset. I've been using this page as reference; if there is a better one that I should be using, that'd be very helpful. code:
Any ideas would be extraordinarily appreciated. e: Problem solved. Thanks. Pay no more attention to the C++ n00b behind the curtain. Mornacale fucked around with this message at 04:32 on Mar 9, 2008 |
# ? Mar 9, 2008 04:07 |
|
You seem to be missing std:: in front of bitset.
|
# ? Mar 9, 2008 04:10 |
|
Mornacale posted:e: Problem solved. Thanks. Pay no more attention to the C++ n00b behind the curtain. The guy below you already posted, but in general, people, if you solve the problem without they board's help, please post the solution! Other people might be wondering what it was.
|
# ? Mar 9, 2008 04:38 |
|
How can I add elements to the beginning of a vector? I essentially want to merge a vector and a string, putting one ahead of the other. I was going to just take the characters from the string, starting with the end, and add them to the beginning of the vector. Unfortunately, I can only find the push_back function, which adds it to the end. Would it be ok to make the string into a vector, then tack on the other vector? edit: Thanks Milde. Super Dude fucked around with this message at 05:16 on Mar 9, 2008 |
# ? Mar 9, 2008 05:06 |
|
Super Dude posted:How can I add elements to the beginning of a vector? I essentially want to merge two vectors of different length, putting one ahead of the other. a.insert(a.begin(), b.begin(), b.end()); That will insert all the elements from b into the beginning of a.
|
# ? Mar 9, 2008 05:15 |
|
If I have a vector 'alphabet', and I want to erase a single element at index j, is this the correct syntax? alphabet.erase(j,1);
|
# ? Mar 9, 2008 06:13 |
|
Super Dude posted:If I have a vector 'alphabet', and I want to erase a single element at index j, is this the correct syntax? There's erase(iterator pos) and erase(iterator first, iterator last). The latter erases a range of elements. You want the former (and with an iterator). You should bookmark this http://www.sgi.com/tech/stl/Vector.html.
|
# ? Mar 9, 2008 06:17 |
|
using erase(j) gives this error:code:
|
# ? Mar 9, 2008 06:27 |
|
Yes, because you need an iterator, not an int. If you really want to do it by index, try alphabet.erase(alphabet.begin() + j). But if j is just a loop counter, you should be using an iterator instead of a counter.
|
# ? Mar 9, 2008 06:35 |
|
Super Dude posted:using erase(j) gives this error:
|
# ? Mar 9, 2008 06:36 |
|
Incoherence posted:erase takes an iterator parameter. You probably want alphabet.erase(alphabet.begin()+j). Why is it this hard? Because the STL is weird. Because iterators are better. Why? 'Cos.
|
# ? Mar 9, 2008 17:18 |
|
more falafel please posted:Because iterators are better. Why? 'Cos. If you implement your std::whatever-algorithms using indexes instead of iterators they will be O(n^2) for linked lists
|
# ? Mar 9, 2008 17:48 |
|
Milde posted:There's erase(iterator pos) and erase(iterator first, iterator last). The latter erases a range of elements. You want the former (and with an iterator). http://www.cppreference.com/ That website is also really awesome for general references on C/C++ standard libraries and other stuff. I use it a lot.
|
# ? Mar 9, 2008 19:30 |
|
At the moment, I'm getting a lot of linker errors when Visual Studio is trying to build a class template. The code compiles fine and dandy, but linker errors are too confusing for me to deduce. The template takes in two types, like so:code:
I'm getting LNK2019 errors. I've looked on the Microsoft resource website, but I couldn't see any similarity between the examples they gave and what I was doing. The errors: http://pastebin.ca/935705 So my question is, where do I start if I want to fix these errors? As far as I can tell, all my code is spelled correctly. EDIT: Moved the errors to pastebin to avoid table breaking. Not So Fast fucked around with this message at 22:10 on Mar 9, 2008 |
# ? Mar 9, 2008 21:43 |
|
Jesus dude, that is some serious table breaking. Also it looks like you're trying to define your template member functions in a separate compilation unit (.cpp file). C++ doesn't allow that. You need to define them in the header.
|
# ? Mar 9, 2008 21:52 |
|
Ah, that fixed it, thanks. Yeah, I had the functions defined in a .cpp file, but didn't realise that it wasn't referenced at all in the header file or the main source code.
|
# ? Mar 9, 2008 22:27 |
|
Super Dude posted:How can I add elements to the beginning of a vector? I essentially want to merge a vector and a string, putting one ahead of the other. I was going to just take the characters from the string, starting with the end, and add them to the beginning of the vector. Unfortunately, I can only find the push_back function, which adds it to the end. Would it be ok to make the string into a vector, then tack on the other vector? I know that this was resolved, but why are you using a vector instead of a deque when you know that you'll be inserting at the beginning? Deques are designed to grow from both ends whereas vectors are not.
|
# ? Mar 9, 2008 23:23 |
|
more falafel please posted:It looks like either the headers are out of date with the libraries you're linking in (unlikely), or you're not linking in the library correctly. Yeah, I'm just a retard. Oh well, I got it working at the very least. Thanks guys.
|
# ? Mar 10, 2008 05:49 |
|
Is it possible to examine the memory space a program resides in from within the program?
|
# ? Mar 10, 2008 06:59 |
|
Thug Bonnet posted:Is it possible to examine the memory space a program resides in from within the program? ...yes, programs can read their own memory. But that can't possibly be what you mean to be asking. What are you trying to do?
|
# ? Mar 10, 2008 08:04 |
|
|
# ? May 6, 2024 03:40 |
|
ShoulderDaemon posted:...yes, programs can read their own memory. But that can't possibly be what you mean to be asking. What are you trying to do? No, that's what I'm asking! I'm just kind of curious, honestly. But how would the program know "where it is" in memory, how large it is, etc. Also, I assume it's not necessarily contiguous..
|
# ? Mar 10, 2008 21:18 |