|
TSDK posted:Yes, you're suppose to delete[] it, even if the array size is 1. Could well be a compiler bug then, although I usually like to dive into the actual asm generated and check it's doing something stupid before declaring that. Double check that elsewhere in the code there's nothing assuming mRefreshBuffer has more than one element. Well, I just finished combing through every use of that buffer with very fine teeth, and nothing out there makes that assumption. DID fix a bug where the new[] could be size 0, but that's unrelated in this case. Didn't find a single problem that could be related. I don't get it, I put in that if statement for deleting and ran the thing with libumem debugging fully on, libumem debugging off, and the standard memory library, and it never sees a problem. Generates the same output every time. I guess for now I'll slap a todo comment in there and write it off as fixed so we can get it integrated, and in the mean time, start combing through the asm. Run it through dbx's access checker, too, but gently caress me that turns a three-minute run time into like six hours, ugh. Anyway, thanks for the help, all. Duly appreciated.
|
# ? Jan 30, 2009 21:55 |
|
|
# ? May 18, 2024 08:17 |
|
Ledneh posted:Well, I just finished combing through every use of that buffer with very fine teeth, and nothing out there makes that assumption. DID fix a bug where the new[] could be size 0, but that's unrelated in this case. Didn't find a single problem that could be related. I could be mistaken, but I think you are allowed to dynamically allocate 0 length arrays (though only dynamically).
|
# ? Jan 31, 2009 00:15 |
|
Hey goons. C++ noob here wondering how to do classes and split it into 3 files. One with the class, one with the functions, and another with the actual program. In order to try to get used to it I tried to make a program that only multiplied one number but it seems I can't even do that. Can you guys tell me where im going wrong?code:
code:
code:
L:ordSilent fucked around with this message at 02:12 on Jan 31, 2009 |
# ? Jan 31, 2009 00:40 |
|
L:ordSilent posted:Can you guys tell me where im going wrong? code:
code:
sklnd fucked around with this message at 01:02 on Jan 31, 2009 |
# ? Jan 31, 2009 00:57 |
|
Plinkey posted:It complies but when I try to use the functions from the DLL (memory allocation function RD_new() ). I get a run time error. It's a "System.DllNotFoundException". The DLL and .lib files are in the build directory and looking stuff up on google isn't helping too much. Any ideas? I'm not familiar with the type of development you're doing, but when I used VB 6 on a past project, I had to run "regsvr32" to get Windows to register any third-party DLL's I wanted to load. http://technet.microsoft.com/en-us/library/bb490985.aspx
|
# ? Jan 31, 2009 01:54 |
|
sklnd posted:what you really want is to include your .h instead, since that has the class definition.
|
# ? Jan 31, 2009 02:08 |
|
The one with the //Header1.h comment.
|
# ? Jan 31, 2009 02:25 |
|
Quick question about references. According to Wikipedia:quote:In many implementations, normal parameter-passing mechanisms often imply an expensive copy operation for large parameters. References qualified with const are a useful way of passing large objects between functions that avoids this overhead... Let's say I'm passing in a large object - a texture, for instance - why do I have to pass it in as a const reference instead of just a non-const reference? Isn't a reference just the address of the variable being passed in? And what if I need to modify the object being passed in? If I can't pass it via const reference, should I just pass it via pointer? Am I terribly confused or slightly on the right track?
|
# ? Jan 31, 2009 04:52 |
|
Non-const reference has different semantics than value-types, which is why they are referring to const references. (i.e. If I see a function that takes a non-const reference, I will assume that it will modify my object. If I see a function that takes an rvalue reference, I will assume that it will destroy my object.) Pointers are useful for pointer-to-array types and for nullable values. You can do whatever you want, though. Also, Wikipedia is not a reference for C++ programming, and it's honestly kinda crap for that purpose.
|
# ? Jan 31, 2009 04:59 |
|
L:ordSilent posted:Hey goons. C++ noob here wondering how to do classes and split it into 3 files. One with the class, one with the functions, and another with the actual program. In order to try to get used to it I tried to make a program that only multiplied one number but it seems I can't even do that. Can you guys tell me where im going wrong? "Don't #include cpp files" was already said, but here's a quick primer on what the distinction between h files and cpp files is: foo.h describes the interface to foo.cpp In other words it makes a promise that certain things will be available in foo.cpp without the compiler having to look at foo.cpp directly. Your source code goes through two processes on its way to become an executable - compiling, and linking. When you compile a program that uses multiple source files, each source file (cpp file) gets compiled into its own "object file". foo.cpp will get compiled into foo.o or foo.obj (depending on your compiler/platform). The key part is that when you compile foo.cpp into foo.obj, and it uses functions that you wrote in bar.cpp, the compiler doesn't need to compile bar.cpp at all. All it needs to know is what the functions/classes/etc in bar.cpp are called and what their methods, arguments, return values etc are. That's what bar.h is for. foo.cpp uses the functions in bar.cpp by including bar.h (not bar.cpp), and foo.cpp can get compiled into foo.obj without knowing or caring what the implementation in bar.cpp looks like. bar.cpp then gets compiled separately into bar.obj. Then, in stage two, linking, another program called a linker (usually automatically invoked by your compiler) will take all the obj files and combine them all into a single executable. Its main job is this: foo.cpp used some functions/classes/whatever defined in bar.cpp. It was able to do this without including bar.cpp directly because bar.h promised that functions/classes/whatever matching those signatures would exist in a different object file linking time. The linker then finds the implementation of these functions/classes/whatever in bar.obj and creates a link between the invocation in foo.obj and the implementation in bar.obj so that the function can be called for real when the executable runs. When I was myself a noob programmer, figuring out how this worked cleared up a lot of things that were confusing the hell out of me when I first discovered that #include'ing cpp files isn't really manageable past one or two source files.
|
# ? Jan 31, 2009 06:40 |
|
Im sorry, I still don't quite get it. can someone kind of illustrate what file im supposed to include where? Im not sure how i can get the header file to use the functions in func.cpp without including it.
|
# ? Feb 1, 2009 09:53 |
|
L:ordSilent posted:Im sorry, I still don't quite get it. can someone kind of illustrate what file im supposed to include where? Im not sure how i can get the header file to use the functions in func.cpp without including it. code:
code:
code:
|
# ? Feb 1, 2009 10:15 |
|
using Microsoft Visual Studio 08 Link errors now ugh L:ordSilent fucked around with this message at 11:43 on Feb 1, 2009 |
# ? Feb 1, 2009 10:52 |
|
L:ordSilent posted:using Microsoft Visual Studio 08 What are the link errors? If they talking about things that are missing, make sure that both .cpp files are actually getting compiled. If they are talking about multiple definitions, make sure that you're not still #including some cpp file. Post the errors. Edit: This is probably not causing your linker error, but there's one more thing about header files that you should probably know when making programs with multiple source files: The C++ compiler is dumb and will not know not to #include for a second time a .h file that has already been #included. For example, if foo.cpp includes bar.h and baz.h, but baz.h also includes bar.h, bar.h will be included twice and the compiler will get very confused. The canonical way to avoid this problem is something called "include guards". These are preprocessor commands that ensure a .h file is included at most once. They look like this, for a file called foo.h: code:
Multiply-including a header normally causes a compile error (not a linker error), so this is not your issue, but you will need to know this as your programs become less trivial. Smackbilly fucked around with this message at 16:55 on Feb 1, 2009 |
# ? Feb 1, 2009 16:43 |
|
Smackbilly posted:What are the link errors? If they talking about things that are missing, make sure that both .cpp files are actually getting compiled.
|
# ? Feb 1, 2009 16:47 |
|
Mustach posted:And that the functions are actually getting defined. Right, and that the definitions match the declarations. If foo.h says: code:
code:
code:
code:
|
# ? Feb 1, 2009 16:58 |
|
For some reason, in my code whenever I enter a number, it only says what the cost of number four is. Here is my code so far, and I cannot figure out what is wrong with my " if else" statements.code:
Vandorin fucked around with this message at 01:54 on Feb 2, 2009 |
# ? Feb 2, 2009 01:50 |
|
Vandorin posted:Does anyone know why my code is only showing the cost for number four? I thought that because I used the "else if" statement, that if the number inputed "DVDnumb" was not equal to four, it would skip the statement until it got until one it was equal to. Turn on "-Wall" in your compiler options and check the warnings you get back.
|
# ? Feb 2, 2009 01:59 |
|
code:
you probably want ==
|
# ? Feb 2, 2009 01:59 |
|
sklnd posted:
When I put the ==, and execute it, all that happens when I type the number in is that it says, "Press any key to continue" without posting any of the data.
|
# ? Feb 2, 2009 02:09 |
|
Vandorin posted:When I put the ==, and execute it, all that happens when I type the number in is that it says, "Press any key to continue" without posting any of the data. Look at how "four" is defined. Also consider why you made a variable for this in the first place.
|
# ? Feb 2, 2009 02:11 |
|
While we're at it, main has a return type. It is int, not void.
|
# ? Feb 2, 2009 02:16 |
|
Avenging Dentist posted:Look at how "four" is defined. Also consider why you made a variable for this in the first place. "four" is a float number, so that it can either be a large number or small, and I made it = DVDfour, so that the person typing would only have to enter "four" instead of DVDfour, since they might not know how to do that.
|
# ? Feb 2, 2009 02:17 |
|
Vandorin posted:"four" is a float number, so that it can either be a large number or small, and I made it = DVDfour, so that the person typing would only have to enter "four" instead of DVDfour, since they might not know how to do that. You really, really need to think about what the input from cin is going to give you.
|
# ? Feb 2, 2009 02:18 |
|
sklnd posted:While we're at it, main has a return type. It is int, not void. My teacher has only told us about void, because he said he hates typing, and that you have to add something at the end, in addition to the closing }.
|
# ? Feb 2, 2009 02:18 |
|
Vandorin posted:My teacher has only told us about void, because he said he hates typing, and that you have to add something at the end, in addition to the closing }. Get a better teacher. void main is not valid c++, and gcc will not even compile with it. http://www.research.att.com/~bs/bs_faq2.html#void-main Also, the something you have to add (return) is not required in main() in c++
|
# ? Feb 2, 2009 02:22 |
|
Avenging Dentist posted:You really, really need to think about what the input from cin is going to give you. edit: I thought it would give me "four" or whatever number was entered, and then the statement " if (DVDnumb == four )" statement would start working? Vandorin fucked around with this message at 02:24 on Feb 2, 2009 |
# ? Feb 2, 2009 02:22 |
|
You have provided us with some great laughs, A+. Uh, just to be sure, you're not a CS major, right?
|
# ? Feb 2, 2009 02:25 |
|
Vandorin posted:edit: I thought it would give me "four" or whatever number was entered, and then the statement " if (DVDnumb == four )" statement would start working? I think you don't understand how variables and literals work yet. You want the literal 4 instead of the variable four, and DVDnumb should be an int instead of a float. Your input should be an integral number (meaning it doesn't have a decimal point).
|
# ? Feb 2, 2009 02:26 |
|
Vandorin posted:edit: I thought it would give me "four" or whatever number was entered, and then the statement " if (DVDnumb == four )" statement would start working? "four" is a string. This is not a string. Think about it this way: What do you want the user to do? (Input some information) What kind of information do you want? (A number, specifically an integer from 1 to 4). What does each possible input correspond to? (A choice from your list of DVDs) How can you tell if the user entered the number 1? (An if statement) And so on
|
# ? Feb 2, 2009 02:30 |
|
Avenging Dentist posted:"four" is a string. This is not a string. OH, ok I understand what you mean now, and my code is working great! , Thank you for helping me each step, haha even though I know I really need to work at this stuff.
|
# ? Feb 2, 2009 02:36 |
|
I have a question no so much about syntax but more of an IDEA on how to do this loving program. I have to do a program using inheritance as the main structure. The idea is to use inheritance to solve a way to find the area of 2D shapes and the surface area/volume of 3D shapes: The parent/child structure should be as follows: I was going to define a macro for every shape's length/width/height (there is no user input) but really have no idea on what to actually REUSE for this assignment. I have two .h files (2D and 3D) with every shape's class defined, but my main remains blank because I have no idea on how to approach this question. Again, not asking for help on syntax or on how to do my homework, just an idea to work with. EDIT: Would this be a valid way? code:
I may be thinking too hard about this. Any help would be great. notMordecai fucked around with this message at 04:10 on Feb 2, 2009 |
# ? Feb 2, 2009 03:39 |
|
Area and Volume virtual functions would be a start.
|
# ? Feb 2, 2009 04:27 |
|
Vandorin posted:My teacher has only told us about void, because he said he hates typing, and that you have to add something at the end, in addition to the closing }.
|
# ? Feb 2, 2009 04:36 |
|
Mustach posted:Your teacher is a piece of poo poo if he gets hung up on something like that. Especially since ISO/IEC 14882 3.6.1 #5 posted:A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing So your teacher is so lazy that he's actually typing more to do the same thing.
|
# ? Feb 2, 2009 04:43 |
|
What's more conventional when using classes out of the STL: "using namespace std;" in each .cpp file in which it matters, individually importing the symbol for each class you're using ("using std::vector", "using std::list" or whatever), or explicitly qualifying every occurrence of the symbol ("for (std::vector<int>::iterator p...")? Is there even a convention? I feel weird pulling in entire namespaces to save myself typing.
|
# ? Feb 2, 2009 06:14 |
|
Avenging Dentist posted:Especially since He probably got confused by the warnings compilers emit when there's a non-void function without a return statement.
|
# ? Feb 2, 2009 06:41 |
|
Scaevolus posted:He probably got confused by the warnings compilers emit when there's a non-void function without a return statement. Huh? code:
Avenging Dentist fucked around with this message at 07:01 on Feb 2, 2009 |
# ? Feb 2, 2009 06:57 |
|
Avenging Dentist posted:Huh? Functions of a return type other than void, which are not main(), that lack an explicit return statement, will generate a warning upon compilation. Scaevolus is speculating the the prof, being obviously fairly bad at C, saw some of these warnings and didn't know that main() was a special case.
|
# ? Feb 2, 2009 07:02 |
|
|
# ? May 18, 2024 08:17 |
|
The Red Baron posted:I posted about my Modern C++ Design-inspired Boost-ified factory patterns some months ago, but I've refined a lot of the code since then and added several new features. I'd really like to hear C&C from some of our resident C++/Boost wizards on what they think of the design/code/documentation etc, and whether or not it seems ready to be submitted to the Boost vault/sandbox any time soon. Anyone? I'm conveniently glancing at TTS and AD
|
# ? Feb 2, 2009 16:26 |