2,898 Posted Topics
Re: The first observation is that you are using floating-point arithmetic (e.g. 2.6 * M - 0.2). The Zeller algorithm is based on the fact that integer arithmetic is used. In other words, (D / 4.0) is not equal to (D / 4), the former is in floating point arithmetic and … | |
Re: There are indeed special rules about virtual functions, especially when they are inlined. But none would explain what you have observed. Basically, the special rules are about allowing the compiler to by-pass the dynamic binding (vtable lookup) in cases where the object type and thus the virtual function call is … | |
Re: Wow, "delete this;"... I can't begin to tell you how unsafe this is. >>is such a method recommended? Here is my scale in C++: - [B]Desirable[/B] (includes things like RAII, exception-safety, binary compatibility, generic implementations, concept checking, const-correctness, etc.) - [B]Recommended[/B] (includes things like programming-by-contract, independence, abstraction, encapsulation, non-copyable, smart … | |
Re: [URL="http://www.cplusplus.com/reference/iostream/ios/exceptions/"]Here[/URL] is an example of how to tell the fstream to throw an exception if something wrong happened, and how to catch the exception. I guess that is what is required to do. The basic mechanism of exceptions in C++ is with the "throw" "try" and "catch" keywords. Their meaning … | |
Re: The bound that you use on the loop is not correct. "length" is the total number of characters in your memory buffer, it is not necessarily the number of characters that was read with fgets from the file. C-style strings are terminated by a null character. So, you should add … | |
Re: **PLEASE USE CODE TAGS** it's horrible to read this post. I did manage to spot this: [ICODE]char *p = strtok((char*)s.c_str(), " ");[/ICODE] You cannot use strtok() with an std::string! What is returned by c_str() is a read-only char array. The c_str function returns a constant pointer, but it should return … | |
Re: If you need the "add" or "union" function to be adding or uniting two sets, then you need to make the function parameter a set: [CODE] template<class T> class set { public: void add(const set<T>& otherSet); void union(const set<T>& otherSet); private: } #include "set.template" //that's weird, btw. [/CODE] And similarly … | |
Re: >>is there anyway I can change this Rgb type to now have the desired stride length? No. All types in C/C++ have a fixed size, that cannot be changed at run-time. No way. If you could change the interface, it would be better to output an iterator object which then … | |
Re: When you pass the object by value (not pointer or reference), a copy of the object is made and used as the parameter. Because the parameter is of type Base, the new object (the copy of the passed object) is of type Base, regardless of the type of the object … | |
Re: Ok, let me clarify what I think you mean. You would like to have a Log class that does something like this: [CODE] class Log { private: std::ofstream outFile; //.. public: Log(const std::string& filename) : outFile(filename) { /*..*/ }; void recordEntry(const std::string& S1) { //.. outFile << S1; }; void … | |
Re: Line 13 and line 17 look awfully similar... wink wink... | |
Re: Why not try it and see for yourself: [CODE] #include <iostream> struct Foo { Foo(bool shouldThrow) { if(shouldThrow) { std::cout << "Foo Constructor called, throwing exception..." << std::endl; throw 42; } else { std::cout << "Foo Constructor called, no throwing anything :)" << std::endl; }; }; ~Foo() { std::cout << … | |
Re: **PLEASE USE CODE TAGS** If you sort the list, using "data.sort()". It will put all the characters in order of their binary representation which you can get from the [URL="http://www.asciitable.com/"]ASCII table[/URL]. You will notice that all numbers are between character #48 and #57. Any character before or after is a … | |
Re: The _start function is something that the compiler generates. It's actually the first function that starts the program (called the entry-point). Nominally, all this function does is call the main() function. If you do not have a main() function defined anywhere (empty source file or whatever), that is the error … | |
Re: Isn't code injection malevolent? I hope you are not one of those despicable hackers. >>I understand this class is VERY POORLY DESIGNED. It's also very incomplete. You are not initializing most of your data members. >>My question is how can i fix this?? The main problem that I see is … | |
Re: The main reason for using const char* is because it is compatible and linkable with C. Many APIs and other libraries have C interfaces (you use the API via a collection of C-like functions). With these functions, you have no choice but to use types that exist in C, which … | |
Re: Whatever it is that is causing this behaviour is not standard. When I tried your program, line 6 would output garbage regardless of line 12 and 14 being commented or not, as expected. It might simply be that your compiler puts "cow" from line 12 temporarily on the stack frame … | |
Re: You have no breaking condition in your getline function. The while loop that uses is.get(), when applied to the standard input stream, will never end. Normally, this loop would end when you hit the end-of-file, but cin never reaches that point, it has no end. When there is nothing remaining … | |
Re: The problem is that string is not just an array of characters. First, the array of characters that it does hold is just big enough for the number of characters the string currently has. In this case, you initialize it to " " so it will contain only one character, … | |
Re: What code do you have so far? What did you try? What is your hold function supposed to do? What is it about this hold function that you don't know how to do or can't seem to make to work? ... >>can anyone help me? We can answer questions or … | |
Re: You mean besides reducing the scope of the std::map object? You can swap it to an empty temporary container: [CODE] int main() { std::map<int,int> my_large_map; //... allocate a large number of elements in map. std::map<int,int>().swap(my_large_map); //swap with an empty temporary //at this point my_large_map is empty and the temporary was … | |
Re: >>frowns on stackoverflow.com where everybody is posting relevant pieces of code to actually help each other and not vague phrases On SO, almost any post that looks anything like a homework/exam question is closed down by moderators in a matter of minutes. Here we rarely shut-down people, we help people … | |
Re: This is a classic problem, you have a dangling new-line character on the input stream. You need to call ignore() right after you input the character to clear that dangling new-line. So, at line 31: [CODE] cin >> ans; cin.ignore(); [/CODE] | |
Re: If you have more than 1900 of debt at 14%, and you only pay 20 per month, you will never be able to repay your debt, ad infinitum. That's why you get an infinite loop. You should add a check at the start of the loop to see if the … | |
Re: call: [CODE] ready.open(apply,ios_base::trunc|ios_base::out); [/CODE] | |
Re: >>Constant pointers mean that once you point to an address, you won't be able to point to anything else? Yes. >>So changing the value of an address that a pointer is pointing to is the only way to change the value of the pointer? The value of a pointer IS … | |
Re: There are several problems with your code: In Header: Line 61 and 62: You are missing the semi-colon at the end of the line. Line 28: You are missing a semi-colon after } Line 52: There should be a closing bracket }; at the end of the DynStack declaration. And … | |
Re: Try using the fastest and least consuming random number generator: rand48 ([URL="http://www.boost.org/doc/libs/1_46_0/doc/html/boost_random/reference.html#boost_random.reference.generators"]here[/URL] is the list of all options). The one you are using is very memory-hungry and is not the fastest. Sometimes, it might be worth exploring [URL="http://en.wikipedia.org/wiki/Quasi-random_number"]quasi-random number[/URL] generators instead (it is found to be faster and just as … | |
Re: It appears that this is just a little compiler flag mismatch. You should follow the instructions [URL="http://tech.groups.yahoo.com/group/OpenCV/message/68131"]here[/URL], and it should work. | |
Re: >>how to use tree and hash tables and linked lists properly using classes. This sounds more like you need a Computer Science textbook. Using trees, heaps, hash tables, self-balancing trees, linked lists, etc. etc., these are computer science topics and they generally differ only on the details when it comes … | |
Re: >>How do you pass an unknown object into a function and save it? It all depends on how "unknown" the object is. There is a big difference between "it could be one of a few different types" and "it could be of absolutely any type that exists or will ever … | |
Re: >>I'm wondering how to correctly link an array to a class. Well, you can link an array to a class, but that's probably not what you want. What you want is to store an array in a class. This can be done like this: [CODE] class MyClass { int values[10]; … | |
Re: Your declaration of Node should come before your declaration of LList. The compiler doesn't know what Node<T> is because this class is only declared later. When it says "expected initializer before < token", it just means that it didn't recognize "Node" in front of "<T>". | |
Re: I think that just an ordinary sleep function would do, no? For example, using boost::thread (I'm not so familiar with native pthread stuff): [CODE] #include <boost/thread/thread.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/bind/bind.hpp> #include <iostream> class foo { public: void my_delayed_method() { std::cout << "Hello World!" << std::endl; }; private: boost::thread delay_thread; void … | |
Re: Your question is: >>When would it be practical to use a pointer to get a value instead of using the value's name? IF you know the variable's name and have access to it, THEN you can use the variable's name instead and there is no reason to use a pointer … | |
Re: Use a loop: [CODE] string name; cout << "Enter You're Name: "; while(name.empty()) getline(cin, name); [/CODE] | |
Re: Line 210 causes a crash, you should never delete a pointer that you didn't allocate yourself. Especially in this case. The pointer returned by str().c_str() is not a pointer that you can delete (the string object will take care of that). This must be the craziest code I have ever … | |
Re: FYI, I launched your program on my home computer (remotely from my office), I will send you the results when I come home later this afternoon. | |
Re: >>Also, there is a lambda function used I would like to remove without adding another function. That's easy. Your Lambda is only calling the isspace function, just replace it with the isspace function. As so: [CODE] sum = std::count_if(left.begin(),left.end(),std::isspace); [/CODE] >>I'm comparing a std::string::difference_type to a std::string::size_type That's ok, it … | |
Re: If you know there is a fixed number of grades/courses, then you actually won't need to check for the newline. If you do want to read until the newline, then you need two steps. First, you read the entire line into a string, and then, you use the string to … | |
Re: I think the only problem is that on line 95 and 103, you are using "alp" instead of "alpha". For the rest, it is correct. To some extent, your use of outputting the value of alpha and beta by passing them by reference is correct but not necessary. If you … | |
![]() | Re: All your huge switch-statement does is: get a seat selection X -> if X is out-of-range or not available, then ask for another seat selection. -> otherwise, reserve seat X Your C++ code for doing this should be no more than 5-6 lines of code long, if you just follow … |
Re: Your stack is a stack of Position objects. You need to push Position objects onto it, not integers. For example, at line 55, you could do this: [CODE] S.push(Position(Start.x -1,Start.y)); [/CODE] | |
Re: Your creation of the [B] matrix is not correct. First, when making a new matrix, the elements of it are not automatically set to zero, you have to do that. Second, at line 145, I think you have the wrong index for S (it should be j, not i). At … | |
Re: Just for the record, if you #include <algorithm>, you can replace lines 20 to 38 in template<>'s code with the following: [CODE] TVec::iterator iter = std::find(v.begin(), v.end(), who); //returns the iterator that matches 'who'. if(iter != v.end() ) { v.erase(iter); std::cout << who << " is removed" << std::endl; } … | |
Re: Here are a few cases with explanation to make it clear what they are: [CODE] class Hop { public: //could be any scope //this defines a nested class/struct inside Hop, this is a _type_ (not data member). struct NStrct{ int nCount; }; //the above nested type can be used to … | |
Re: Your question makes very little sense. I think you have a confused idea of "heap". There are two things that are commonly referred to as a "heap". Formally, a heap is a type of data tree-structure typically used for implementing a priority queue. [URL="http://en.wikipedia.org/wiki/Heap_%28data_structure%29"]Wiki[/URL]. Colloquially, people say "heap-allocated memory" or … | |
Re: Make search in all your makefiles for the keyword "-Wstrict-prototypes" and remove it. This is a compiler option that is not necessary (i.e. just a warning) and it must be specified literally somewhere in the makefile (or in many makefiles) so you should be able to just remove it. If … | |
Re: Well. Qt has fairly straight-forward OpenGL support through the QGLWidget, for example this simple [URL="http://www.digitalfanatics.org/projects/qt_tutorial/chapter14.html"]NeHe tutorials in Qt[/URL]. For all the pan/rotate/zoom and select operations, I'm not sure if there are much off-the-shelf components or actions that can do this. Fortunately, this isn't all that hard to implement with OpenGL … | |
Re: yes, but I would still recommend making the initial value explicit (as in [ICODE]stinker() : pointer(NULL), age(0) { };[/ICODE]. You are basically asking the person who reads your code to be aware of "value-initialization of POD type means zero-initialization". This is not so common (many people wouldn't even know the … |
The End.