|
Somehow I managed to screw up (and save) my sourceannotations.h file, and it's now giving me errors which are beyond my comprehension. Where can I get a fresh sourceannotations.h file?
|
# ? Mar 3, 2009 13:39 |
|
|
# ? Apr 24, 2024 11:17 |
|
That Turkey Story posted:Boost.Thread I swore I read somewhere this only works for threads launched by boost::thread, but I can't find any reference to this in the docs. I'll check it out, thanks.
|
# ? Mar 3, 2009 17:47 |
|
Not too sure if this is the right place to ask but I thought I'd start here before I created my own thread. I'm trying to make a till system that puts the amount that the user inputs into an array but the numbers stored seem to be random and when displaying the total it always seems to be 2.3125 even if the user just entered 1. Do I need to format it or something? I have no idea what to do now. Sorry the codes pretty messy, I've been trying a number of things and I removed half of it so it doesn't take up a whole page. code:
|
# ? Mar 3, 2009 19:04 |
|
You need to initialise your variables, also learn how to format your code properly and break your lines please. Also spot the error in these lines: code:
|
# ? Mar 3, 2009 19:25 |
|
Thanks very much. It seems to work fine now, pretty simple mistake that I should of spotted. Also the error... should be declared as float instead of int? But I get an error if I do "invalid types 'float[6][float]' for array subscript" Just out of interest what level of C++ would you say this is? Pretty basic or...?
|
# ? Mar 3, 2009 22:53 |
|
This is fundamental basics, pretty much. The error here: your array is size 6 (elements 0 through 5), but your loop is iterating and accessing that array from 0 to 9. Six through nine aren't allocated to your array, so you're writing to memory out of bounds, which is a buffer overrun. This has consequences that can be felt immediately or later down the line, depending on which bits of memory got written in the overrun (which could be bloody well anything). C++ doesn't point this stuff out (some memory libraries do, but that's a debugging function, mainly). You're left to your own devices to make sure you don't overrun arrays, delete memory you didn't mean to, and that sort of fing.
|
# ? Mar 3, 2009 23:22 |
|
MrMartyn posted:Thanks very much. It seems to work fine now, pretty simple mistake that I should of spotted. Also the error... should be declared as float instead of int? But I get an error if I do "invalid types 'float[6][float]' for array subscript" When you declare a static array, what you type inside a bracket can only be a number, which tells the compiler what size the array should be. Writing 'float' doesn't make much sense (which seems to be what you're doing, given the error, but it's generally better if you post the actual code you changed). And yes, this is very basic C++. No classes, using lots of global variables, messy formatting (primarily due to trying to make pretty text output manually). Vinterstum fucked around with this message at 23:33 on Mar 3, 2009 |
# ? Mar 3, 2009 23:23 |
|
I've been creating a polynomial class, and have been having trouble on the input operator. this is what I have so far, but when it prompts, it just spits out the first part of the polynomial (which isn't part of the loop), or it hangs if i modify the while loop. My professor wrote down ways to end the loop, but i'm not sure how to implement them in the loop. (she wrote down white space, character not digit, x, ^, +, -) Am I doing the entire thing wrong? Any ideas? Thanks. The class is called polynomial, and it has two private variables; int d (degree of coefficient), and int * c (coefficient). code:
|
# ? Mar 6, 2009 03:42 |
|
I'm really irritated that I can't figure this out, it's pretty much a first year university question, but I'm pretty rusty when it comes to this stuff (been doing C# a lot lately). I'm trying to write a templated Linked List in C++: LinkedList.h: code:
code:
|
# ? Mar 6, 2009 05:24 |
|
In brief, you will need to put all of your templated function definitions in the header file; that's just how it works. Slightly more detail: the compiler needs to know the full definition of the templated function at (basically) every point of instantiation. There is something in the formal spec which achieves this while still kindof-sortof maintaining separate compilation, but it is very rarely implemented. rjmccall fucked around with this message at 05:37 on Mar 6, 2009 |
# ? Mar 6, 2009 05:33 |
|
Morpheus posted:it says it can't find the constructor.. All code needs to be in the .h file and you don't need <T> after member functions, but you do need it for the pointer though (I think). LinkedList.h: code:
|
# ? Mar 6, 2009 05:40 |
|
Morpheus posted:Seems pretty simple, right? Only trying to instantiate a LinkedList pointer makes a linking error, it says it can't find the constructor. If I put the constructor in the header (ie LinkedList<T>() { length=0; }) creates no error. I just need to know wtf is going on here. That's pretty much the only way to do it. The compiler needs the code available when the template is instantiated, so it needs to be in the header.
|
# ? Mar 6, 2009 05:52 |
|
Contero posted:All code needs to be in the .h file and you don't need <T> after member functions, but you do need it for the pointer though (I think). Incorrect.
|
# ? Mar 6, 2009 06:32 |
|
Avenging Dentist posted:Incorrect. drat. Well you still don't need it after the constructor in the class declaration like he had it. Should be: code:
|
# ? Mar 6, 2009 07:41 |
|
weldon posted:I've been creating a polynomial class, and have been having trouble on the input operator. quote:My professor wrote down ways to end the loop, but i'm not sure how to implement them in the loop. (she wrote down white space, character not digit, x, ^, +, -) quote:Am I doing the entire thing wrong? Any ideas? Thanks. Write a function that reads one monomial and returns the coefficient and power. Then your polynomial input function just has to call the monomial input function repeatedly. You can test your monomial input separately and fix its bugs. code:
You're using "peek" and "get" inconsistently - why is there a ins.peek() by itself, without the return value being used? (When I stopped the code in a debugger, this is where it was looping.) Using istream::putback is simpler than using get and peek. So instead of your while loop, code:
Pooball fucked around with this message at 12:02 on Mar 6, 2009 |
# ? Mar 6, 2009 12:00 |
|
Folks posted:lotta helps Ah, I see...damnit though. This is why I do not like programming in C++ if I can avoid it, this weird poo poo. Oh well.
|
# ? Mar 6, 2009 14:30 |
|
I've never quite worked out what the scope of a typedef is. If I have a header file myheader.h :code:
|
# ? Mar 6, 2009 15:41 |
|
DoctorTristan posted:I've never quite worked out what the scope of a typedef is. If I have a header file myheader.h :
|
# ? Mar 6, 2009 16:19 |
|
Pooball posted:What development environment are you using? Can you use a debugger? Otherwise, put in print statements.
|
# ? Mar 6, 2009 18:28 |
|
quote:Should the else if be a +, since its starting a new term? Possibly. You probably want to handle 'x' as well for the first term and avoid faking a '+' - are you assuming the first term will be positive? quote:or should i have multiple else if statemnts? When would the for loop end?
|
# ? Mar 6, 2009 18:47 |
|
Pooball posted:Possibly. You probably want to handle 'x' as well for the first term and avoid faking a '+' - are you assuming the first term will be positive? Well because the way the array of coefficents are stored (backwards) I read in the first part, make a dynamic array = to its degree, and then keep reading in. Thus, the loop basicly starts with a + or a -, with no white space. If it is a +, it should be ignored, but obviously if it is a - it probably belongs to a number, so I would want to use it as the coefficient of the following number. In your example, where would you start to store the variables? You would only want to store them after you have a degree and coefficent that work, and be able to ignore missing ones (ie the 0x^3 from 2x^4+2x^2).
|
# ? Mar 6, 2009 19:06 |
|
Me again. Trying to do operator overloading, a subject which I have not a lot of experience in, and I am getting a funky error.code:
The error? - cannot convert from 'LinkedList<T>' to 'Thing*' I don't know wtf. It doesn't even get to my code, it just looks at the one line and says "Well gently caress that". Morpheus fucked around with this message at 00:36 on Mar 7, 2009 |
# ? Mar 7, 2009 00:32 |
|
That is really not enough information, but I will make a guess anyway. I suppose your code looks like this:code:
code:
code:
|
# ? Mar 7, 2009 01:18 |
|
rjmccall posted:That is really not enough information, but I will make a guess anyway. I suppose your code looks like this: You got it right. Really, I'd need to do that? Hmm. I might as well use .Get(int). Not as nice-looking, but surrounding my list name with parentheses every time I want to use the [] operator, or what you were doing in the second one seem even worse. Thanks for the help! Errors like this are what turned me off C++ in the first place.
|
# ? Mar 7, 2009 01:29 |
|
Morpheus posted:You got it right. Really, I'd need to do that? Hmm. I might as well use .Get(int). Not as nice-looking, but surrounding my list name with parentheses every time I want to use the [] operator, or what you were doing in the second one seem even worse. Thanks for the help! Errors like this are what turned me off C++ in the first place. You overload operators on your type. You cannot overload operators on pointers to your type, because pointers are a built-in type. This makes a lot of sense and totally does not get in your way if you just used references instead of pointers.
|
# ? Mar 7, 2009 01:33 |
|
Morpheus posted:You got it right. Really, I'd need to do that? Hmm. I might as well use .Get(int). Not as nice-looking, but surrounding my list name with parentheses every time I want to use the [] operator, or what you were doing in the second one seem even worse. Thanks for the help! Errors like this are what turned me off C++ in the first place. If you're not clear on the difference between pointer and non-pointer types (and you obviously aren't), you're going to have a hell of a time with C++.
|
# ? Mar 7, 2009 01:34 |
|
Passing it around by reference (the second option) is pretty reasonable if you get it as a reference in the first place (e.g. you created it as a variable or a member). The only problem is really if you heap-allocated it, but there usually aren't compelling reasons to directly heap-allocate data structures like that. EDIT: That's not really a defense of this particular obnoxiousness of C++, of course. But having special syntax for it (e.g. Perl's ->[]) would be somewhat terrible, since it would be very easy to accidentally use the wrong syntax — although that would usually be caught by the compiler. rjmccall fucked around with this message at 01:37 on Mar 7, 2009 |
# ? Mar 7, 2009 01:34 |
|
If life gives you pointers, dereference them and make references. Or something.
|
# ? Mar 7, 2009 01:38 |
|
Avenging Dentist posted:If you're not clear on the difference between pointer and non-pointer types (and you obviously aren't), you're going to have a hell of a time with C++. That's the funny thing, I've programmed with C++ for maybe a year, two years. I stopped for a while, did a lot of C# and Java, and now coming back to this is just a whole lot of playing catch-up with myself, and I'm running into problems I've never run into before for some reason.
|
# ? Mar 7, 2009 01:45 |
|
Right now i am doing a project for my group project class this class is basically heralded as a right of passage for CS students. Were doing this project using Rational Rose (). Anyways right now its telling me that i need to overload the copy operator for this class, except i don't understand why i would need to. code:
|
# ? Mar 7, 2009 01:52 |
|
That code shouldn't compile. You have mismatched parens and no semicolon at the end.
|
# ? Mar 7, 2009 02:01 |
|
Avenging Dentist posted:That code shouldn't compile. You have mismatched parens and no semicolon at the end. Sorry, i don't actually have the source of it since rational rose is a UML/automatic code generator/other terrible things. I was basically just trying to turn what i have in their gui into code. Is it even possible to create a copy constructor really for a class like that though? Since rep is a const pair? It cannot be modified correct? So a copy constructor can't really change anything in this case?
|
# ? Mar 7, 2009 02:42 |
|
UberJumper posted:Is it even possible to create a copy constructor really for a class like that though? Since rep is a const pair? It cannot be modified correct? So a copy constructor can't really change anything in this case? code:
|
# ? Mar 7, 2009 02:52 |
|
UberJumper posted:Is it even possible to create a copy constructor really for a class like that though? Since rep is a const pair? It cannot be modified correct? So a copy constructor can't really change anything in this case? You are thinking about an assignment operator, which is not the same thing as a copy constructor.
|
# ? Mar 7, 2009 02:56 |
|
Fullets posted:
That would be perfect. But since rational rose doesnt offer a way to use initalizer lists with copy constructors. Is there someway to get freaky with const'ness and completely remove the constness?
|
# ? Mar 7, 2009 03:02 |
|
I don't understand your problem. Rational Rose will generate some stubs for you. Then you go in and fill out those stubs. Besides that, the default copy constructor is sufficient, and you don't actually need to type it out.
|
# ? Mar 7, 2009 03:30 |
|
Avenging Dentist posted:I don't understand your problem. Rational Rose will generate some stubs for you. Then you go in and fill out those stubs. Besides that, the default copy constructor is sufficient, and you don't actually need to type it out. What do you mean by stubs? If your refering to the generated C++ code, the problem is if i modify those, once i rebuild i will have to go back and rebuild them. Since for this project it is emulating a client/server model using connexis. The applications are run within rose. Rational rose is basically FUBAR at my university(were using roseRT 1997? i think.) It never works right, and does wonderfully werid things, e.g. demanding a copy constructor or saying the data type for an unsigned int is too complex and needs to be defined manually. I know it should be smart enough to generate one, but for this little example it is not. Ether way i managed to figure out a way of doing it. Once you define a wonderful copy constructor a magical field under RoseRTS appears! CopyConsturctorInitalizer. Thanks though.
|
# ? Mar 7, 2009 03:39 |
|
I have a function:code:
Is there any way, at compile time, to enforce then x can only be certain values, without breaking interface? Macros are fine. If I am willing to break the interface, can templates and/or Macros solve this problem easily? Chuu fucked around with this message at 09:01 on Mar 7, 2009 |
# ? Mar 7, 2009 08:48 |
|
Chuu posted:I have a function: You can use Boost Static Asserts or roll your own Static Asserts (it's not hard using template trickery.) Here's the Boost ones, I'm sure you can find an implementation of your own if you look around. http://www.boost.org/doc/libs/1_31_0/libs/static_assert/static_assert.htm
|
# ? Mar 7, 2009 09:30 |
|
|
# ? Apr 24, 2024 11:17 |
|
Chuu posted:I have a function: Why not void doSomething(myEnum x)? EDIT: Oh also static asserts won't work because the value of x is known only at runtime.
|
# ? Mar 7, 2009 10:06 |