2,898 Posted Topics
Re: I have no idea what a $ sign does in a macro, if it even does something at all. As far as I know, the $ sign is not a reserved character and is not used for anything in C/C++, so I would imagine that it is a valid character … | |
Re: I would go one step further than gerard4143, I would say that it is not only O.K., but considered better practice in C++ to declare variables only where they are needed. In theory, it is faster. In practice it is just nicer because it keeps things localized in the code. … | |
Re: **I couldn't watch the video, it requires SilverLight which I don't want to bother installing. Off the bat, I would have to say that if you plan to make anything more complex than a few very simple GUI elements, just bare-bone Win32 API is probably not what you would want … | |
Re: @AnnnDi: there are a few small problems with your program: First, the srand() function only needs to be called once. So put one call to this function somewhere at the start of the program (either at the start of WinMain or at the OnCreate of your main form or something … | |
Re: >>Do you enjoy ruining peoples' lives like that? The truth is better than false illusions. >>If I knew EXACTLY how the whole process was done in every instance I'd do it, Where does this logic end? Have you thought about that? You seem to be saying: I don't want to … | |
Re: This line is the problem (line 18): [CODE] inFile.read((char*)&Value1, sizeof(string)); [/CODE] You have to understand that string is not like primitive types (like int or float or char), it is a class. This means that an object of class string is not as "simple" as a primitive type. So, simply … | |
Re: The code that you used is correct in some sense. Whether the character that is displayed on the screen when you run the program is not a matter of how the program is written or how it is compiled. It is a matter of which environment you are running the … | |
Re: >>I thought that because main() doesn't end yet, all the members and variables that were created inside it would still be available to all the other functions in the program. You're logic is correct but there is another aspect that you are neglecting. Yes, variables that you declare in main … | |
Re: May I suggest that you read the [URL="http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12"]following explanation[/URL]. One solution to your problem is explicit instantiation of the template. [URL="http://programmingexamples.net/index.php?title=CPP/Templates/FunctionTemplateExplicitInstantiation"]Here[/URL] is an example of a function template. This is, of course, only applicable if you have a reasonably small amount of predetermined types for which your template could be … | |
Re: As said, if you look on any page at [url]http://www.cplusplus.com/reference/[/url] say [URL="http://www.cplusplus.com/reference/stl/vector/"]this one[/URL] on vector for example, you will find in the top right corner the #include needed for this class or function (in the case of vector, it is #include <vector>, if that wasn't obvious enough already). | |
Re: I'm not sure I understand what you mean with the whole interpreted language application stuff. But, all you need to make that little snippet of code work is to forward-declare the types. Specifically, you can add the following at the very beginning of the code you posted: [CODE] class b; … | |
Re: You are doing it correctly. Except, you are not giving a value to the y pointer when you are creating the object of class B without parameters (i.e. in the default constructor). This would mean that your pointer y will have an uninitialized (and thus invalid) value and deleting that … | |
Re: Zjarek is correct. And the error message is related to the fact that the use of [] without anything inside of it is only permitted in a few cases (when declaring a parameter to a function or when declaring a static array whose size is determined by its initializer), in … | |
Re: **Please use code tags** I don't really understand your question. The vector class in the STL is already an implementation of a stack (in fact almost all basic STL containers are). With either vector or list: - to push an element on the stack, you use [URL="http://www.cplusplus.com/reference/stl/vector/push_back/"]push_back[/URL]() - to pop … | |
Re: @Transcendant: If you are still having trouble with making this program work, I suggest you create a fresh new thread for it (because this thread seem to have about two posts related to the question out of 25 or so). I'm sorry (on "behalf" of daniweb) for the flame war … | |
Re: Three points to make here: 1) The error is caused by the fact that you are changing the size of the vector at line 67 by calling erase() on it. Once you change the size, the iterator is invalid. You could refrain from modifying the length of the vector in … | |
Re: As for the GCC downloads, if it is still relevant to you: gcc-4.5.2.tar.bz2 -> this is the compiler(s) and standard libraries (this is the one to download) gcc-ada-4.5.2.tar.gz -> this has the ADA compiler (most probably useless to you) gcc-testsuite-4.5.2.tar.gz -> this is if you want to test that GCC … | |
Re: Converting a double to an integer is not a trivial operation because they are represented completely differently in binary. It is not like conversions between integer types where it's almost just a matter of changing the number of bits. Like L7Sqr has reported, I would expect the conversion from double … | |
Re: If you have your own "home-brewed" project that you could make open-source, then what do you think is better on a résumé: "I have worked on a little home project, and I think it's good." OR "I have started an open-source project, got several people on-board, managed to coordinate the … | |
Re: I very often use the flush for displaying the simulation time without printing lines after lines. Say I run a numerical simulation in big loop, I would insert in it: [CODE] while (..) { //... all the simulation code //print the current simulation time over the last one printed (without … | |
Re: Just a thought. You could also use the [URL="http://www.boost.org/doc/libs/1_45_0/doc/html/variant.html"]Boost.Variant[/URL] to solve your problem. Just return a boost::variant with all the possible image types. It's not pretty, but it'll work. Still better than violating type safety. If your image types are comparable in size, it might be a good alternative. Personally, … | |
Re: You need to compile both cpp files in the same compilation: [CODE] $ g++ HelloApp.cpp Hello.cpp -Wall -o HelloApp [/CODE] Or, on an IDE (like VS or Code.Blocks), you would need to add all the .cpp files to the list of "source files" for the project (or solution). | |
Re: This problem is just a matter of the types of "intarray" and "begllts and endllts". If they are of the same type (or compatible types), then you need to show the definition of those types. If they are the same and are primitive types like "int", then there is something … | |
Re: The typedef that you have shown is a typedef for a "function pointer" type. The format is a bit different than other "normal" typedefs. Here would be the simple format of such a typedef: [CODE] [B]typedef[/B] [I]return_type[/I] ([[I]calling_convention[/I]] *[B]identifier[/B]) ( [I]parameter_list[/I] ); [/CODE] This means that the following function signature … | |
Re: I think the easiest way to generate your numbers might be something like this: [CODE] double d = (rand() % 3000 - 1500) * 0.001; d = ( d > 0.0 ? d : 0.0); [/CODE] This way, roughly half of the numbers will be zero and the other half … | |
Re: Overall it is quite ok. I mean, you use indentation correctly, which is important. Your variable names are clear, which is also very important. You did put a lot of comments, which is important for the professor (but not really for any programmer that I know of). It is a … | |
Re: @Baluba: Borland C++ 3.1 dates back to 1992. It's a 16bit compiler for Windows 3.1. That's prehistoric dude! There has been almost 3 revisions of the C++ standard since then and plenty of extensions to the standard libraries too. @L3gacy and VernonDozier: If you want the very latest gcc (with … | |
Re: I would try defining the Iterator type with a typename: [CODE] //in SList class declaration: typedef typename SListIterator<generic> Iterator; [/CODE] Please post the entire error message (it is cut-off in the thread's title). | |
Re: As far as I know, this expression: [CODE](("%s",shared_memory) == "How are you my child?")[/CODE] will always evaluate to false. The first part "("%s",shared_memory)" will first evaluate "%s", which does nothing, and then evaluate shared_memory, which does nothing, and then return the value of "shared_memory" which is a pointer. Then, the … | |
Re: I think you counted one 6 too few in that last post about the differences. Also, with the numbers "f(8) = 24", "f(16) = 64", "f(32) = 160"... and the formula "f(n) = O(nlogn)"... I mean.. talk about obvious! I'm no psychic, but I would predict also that "f(64) = … | |
Re: Your constructor for "testType" has no implementation. So the linker is looking for one and doesn't find it and thus throws: "unresolved external reference" (these words mean that your "reference" in the code, which is the call to the constructor, is assumed to be "external", i.e. found in another compiled … | |
Re: You have to understand that these expected errors are upper-bounds. I would think the messy curves you see (which is called "variance" btw) mostly have to do with the particular function used. For example, when the range includes a zero-crossing, then the way that the intervals (the small sub-divided intervals) … | |
Re: Add the keyword "inline" in front of ALL function implementations, as so: [CODE] template <> inline void Matrix<double>::CopyData(double* dest, double* src, unsigned count) [/CODE] That should fix your problem. | |
Re: I find it easy to avoid .NET because I don't see any purpose for it in my own projects (and I don't program with Microsoft products anyways). It is clear that for all basic programming purposes, .NET is not needed. Just stick to the C++ standard libraries (and no managed … | |
Re: Well, from the [URL="http://www.cppreference.com/wiki/keywords/static_cast"]reference page[/URL] on static_cast: [QUOTE]It can also cast pointers or references down and across the hierarchy as long as such conversion is available and unambiguous. No runtime checks are performed. [/QUOTE] You see, static_cast is a compile-time casting operator. It will never do runtime checks (in fact … | |
Re: Because an integer can span over several characters (like 1312, i.e. 4 characters), the stringstream finds, by default, the first and longest sequence of characters that constitutes a valid number. And discarding leading 0 characters because in any base, leading zeros are meaningless. But, of course, if you have only … | |
Re: These questions are designed to see if you know the right tools for the job. Of course, these two questions are extremely simple and they surely don't expect you not to be able to come up with a code that does that. What they are looking for is to see … | |
Re: Are you sure that "glutil.h" is actually getting included correctly (i.e. have you set the include path). This is the only source of error I can see here. BTW: you are aware that this glutil library that you are using is far from unique. Just google glutil and you will … | |
Re: Maybe I'm crazy, but isn't your code just equivalent to something like this: [CODE]int x = 0; void myAdd(const double& p) { x = x % 101; ++x; ... (do something to p) }[/CODE] | |
Re: First of all, do not use the line "using namespace std;" (or any other namespace) inside a header file. This is bad. You are not supposed to dump a namespace in a header file (it will make people who use your library (including yourself) very angry in the future). I … | |
Re: >>You don't think it's an issue with the compiler... It is definitely not an issue with the compiler. You can rule that out. If there is anywhere in your code a repetition of the form "class player {", then one of them must go. Make sure you use the header … | |
Re: "advanced typedefs"!??!? Almost all libraries have a number of typedefs (in addition to their classes and functions) to make things convenient (and more abstract). You might want to take a look at [URL="http://www.boost.org"]Boost[/URL]. You'll find plenty of "advanced typedefs" there. | |
Re: 1) This line: [CODE] class OSG_EXPORT Group : public Node [/CODE] means that the class Group can be exported. This if because when you compile this code into a shared library (.so or .dll), you can [URL="http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx#CppNaiveApproach"]export the entire class[/URL]. This is rarely used in practice because there are binary … | |
Re: The basic problem in all the codes that you put is this line: [CODE] std::vector <A<y>* > vec; [/CODE] This suggest that you are trying to instantiate a class template A with an integer variable y. This is impossible. All template arguments that are of some primitive type (like int) … | |
Re: You can get something like [URL="http://qt.nokia.com/products/developer-tools/"]Qt Creator[/URL] for doing GUI stuff and play around with tutorials (like David mentioned). I find that going through tutorial examples is a good way to do something more than trivial console applications without requiring deep understanding yet (if you don't understand, you just reproduce … | |
Re: Normally, the error you are getting should occur when you operate on "it" (the iterator in Project). It should not occur during the use of the function empty(). This is not normal. Unless you have corrupted the memory somehow, this error should not occur. Make sure it is really occurring … | |
Re: This should help you understand what is going on (compile, run and play with this): [CODE] int main(int argc, char *argv[]) { cout << "the 0th argument is: " << argv[0] << endl; cout << "it first two chars are: " << argv[0][0] << " " << argv[0][1] << endl; … | |
Re: You are asking which language you should program in.. on a C++ forum! I think you know where this is going to lead. C++ plays the central role in the world of computer programming. What that means is that all other languages define themselves in comparison to C++. It means … | |
Re: If you are doing a lot of work with strings (I assume parsing), here are some general options to consider (from simplest to most powerful): - [URL="http://www.cplusplus.com/reference/iostream/stringstream/"]stringstream[/URL] (basic string operations, like an I/O stream) - [URL="http://www.boost.org/doc/libs/1_45_0/libs/regex/doc/html/index.html"]Boost.Regex[/URL] (Regular expressions) - [URL="http://www.boost.org/doc/libs/1_45_0/libs/tokenizer/index.html"]Boost.Tokenizer[/URL] (splitting strings into tokens and manipulating them) - [URL="http://www.boost.org/doc/libs/1_45_0/libs/spirit/doc/html/index.html"]Boost.Spirit[/URL] (LL … | |
Re: I think I understand what you want to do, so let me put up a more consistent code and you tell me if that is what your question was about: In Foo.h: [CODE] class Foo { private: int value; public: void PrintValue(); void SetValue(int aValue); }; [/CODE] In FooPrint.cpp: [CODE] … |
The End.