2,898 Posted Topics
Re: Usually if it makes sense to you, it will make sense to others, given the proper documentation. Whether your code is to be published or not does not make a difference because you should always write your code as if it was to be published. Put care into thinking about … | |
Re: >>I expect the copy constructor should be called after the temp object is created. >>But why no "copy" is displayed? Because the second line "D d1 = D(23);" is an explicit conversion. One way to look at it is in terms of optimization, that is, this is a trivial case … | |
Re: I think that [URL="http://www.boost.org/doc/libs/1_44_0/doc/html/thread.html"]Boost.Thread[/URL] is by far the easiest solution (I'm not sure how well it is usable on Solaris, but I presume it is alright.. at leas the latest version). Here is how I would do it: [CODE] #include <boost/thread.hpp> class MyClass { //blablabla //need to provide a copy-constructor … | |
Re: There are just a few mistakes (proper indentation helps to see these mistakes): [CODE] char large(char *p,int a) { int large=0,x=0,b; //x should start at zero. char r; for (int i=0;i<a;i++) { for(int j=0;j<a;j++) { if(*(p+j)==*(p+i)) //notice the difference here *(p+i) instead of *p+i, and the i != j is … | |
Re: I would recommend that you simply comment out all the code in main() and put the lines back in one at a time and check the output. This is a good exercise to understand how objects are created and assigned to values, but it is for you to work out … | |
Re: First, I recommend you use a boost::shared_ptr for all "next" pointers and a boost::weak_ptr for all "prev" pointers, this will allow you to get rid of your destructor altogether. Second, you should think whether you really need a copy-constructor for your queue. If you don't need it, make the class … | |
Re: I think you should make all those data members under the "protected" scope instead of "private", that would solve all your problems. | |
Re: Between line 17 and 18, add the following: [CODE] first = NULL; last = NULL; [/CODE] | |
Re: You must show the declaration of CharQueue in order to find the mistake. For ArrayCharQueue class to be abstract, it means that the CharQueue is abstract (has a pure method ("= 0;") that is not implemented in the ArrayCharQueue class). | |
Re: It might be possible that the DLL function throws an exception, and exceptions cannot cross module boundaries (you cannot throw an exception in a DLL and catch it in the exe). That could be the source of the problem. Maybe you can try to wrap the entire function ProcessCommand with … | |
Re: If you want a fixed number of iterations, use an integer value to control the iteration number and progress. [CODE] for (int i = 0; i < MaxIter; ++i) { double x = dx * i; // numeric code } [/CODE] Many numerical methods do not require a fixed amount … | |
Re: For basic 2D drawings, there are a few options that I can think of. First, if you don't need to have much of a Graphical User Interface, Simple DirectMedia Layer ([URL="http://www.libsdl.org/"]SDL[/URL]) is quite easy to use and allows you to draw simple shapes (circles, lines, rectangles, text, etc.). Second, if … | |
Re: Since the compiler uses the type of the parameter to figure out which template to instantiate, the only information it has is the type of the parameter, it cannot "back-trace" the type from which this parameter type comes from. This is because it cannot assume that the only type T … | |
Re: Being a robotics engineer, I feel a bit obligated to answer... but also very happy to do so, however, your question is too vague, thus, my answer will be as well. >>learn the SDK in C++ What SDK? What is the platform? Is it the LEGO Mindstorm? Or a micro-processor, … | |
Re: As ixmike pointed out, c is useless, and most importantly, i is not initialized (and should probably be an integer, int, and not a double). Now, the input of p and the condition for the loop are not correct. The thing that you have to notice in this problem is … | |
Re: Try to reinstall the build-essential package (uninstall and reinstall). That's the only suggestion I can think of... hope it helps. | |
Re: I think that your cast to LPCWSTR is not correct. Read [URL="http://www.codeproject.com/KB/string/cppstringguide1.aspx"]this article[/URL] for a deeper explanation. | |
Re: >>I m a computer engg student & m absolutly unable 2 undrstand c++. Cn any1 sggst sme buks or ways 2 stdy C++??????? I have a book to suggest: an English dictionary! Communication is one of the most important skills in engineering. | |
Re: Making a Plugin System is not a trivial task... One of my friends who is very experienced tried and gave up. I made one (for windows) four years ago, and it took me about 1.5 years to get it to work properly. Now, I started a new one about 1 … | |
Re: Well, I don't agree with AD about how writing beyond an array will corrupt the heap, it might throw an Access Violation or segmentation fault, but not corrupt the heap (it would be wonderful if it did, it would make heap-related bugs so much easier to find! I know by … | |
Re: This implementation is called the "dreaded diamond", this [URL="http://www.parashift.com/c++-faq/multiple-inheritance.html#faq-25.8"]faq[/URL] is very explanatory. @arshad:>>My respect for Visual studio has increased after reading your comment @Fbody:>>Users of VC++ are the lucky ones MY respect for Visual studio has _decreased_ (even more) since I saw your post. I tried to find a part … | |
Re: Your problem is that the constructors for TwoDimensionalShape and ThreeDimensionalShape do not carry the parameters over to the base class Shape: [CODE] //This is what you had: TwoDimensionalShape(double x,double y) { double Shape(double x,double y); } //This is what it should be: TwoDimensionalShape(double x,double y) : Shape(x,y) { }; //and … | |
Re: As pointed out by Fbody, your copy-constructor has not a single statement that sets the mHead and mTail pointer to anything. The fact that the copied list outputs the list without the head node, is pure luck, it should just output random shit or simply crash on a segmentation fault. … | |
Re: The main problem is that you need to get rid of header stdlib.h it corrupts the call to getline. One simple error is that your file in the search function should be of type "ifstream" not "ofstream", calling a getline on an ofstream will likely lead to an abnormal termination … | |
Re: There are two main reasons people ever use "char*" in C++: either they haven't learned std::string yet (meaning they are within a few weeks of having started to learn C/C++); or they are writing code that interfaces to a C library or an API written in C. If that is … | |
Re: The point about reformatting is that you can spot mistakes in your code much more easily when the indentation is done properly. As a result, most programmers that have more than a few months of experience in coding are already fanatical about respecting format. It certainly won't magically fix any … | |
Re: >>Am I incrementing the address correctly or not? No. The problem is that the expression "&ch + i" takes the address for the pointer "ch" and increments that address by "i". Now, the address of the pointer "ch" is a pointer to a pointer to a char, i.e. "char**". Since … | |
Re: 1. The function you are trying to implement is usually referred to as "concatenation" (or just "cat" for short). I'm just pointing that out to help you build a technical vocabulary for computer science. 2. There are already functions that implement this functionality. I'm sure you knew that, but just … | |
Re: This requires dynamic polymorphism (i.e. base class and some derived classes). A simple way to do it: [CODE] //a very simple base class with one virtual function (required for RTTI). struct stack_element { virtual ~stack_element() { }; }; //a general class template for holding a primitive value template <class T> … | |
Re: The variables arr and maxVarHolder are already pointers to int, using the star * will dereference those into the int variable they point to. The stars are not correct. This will work: [CODE] result = sumarr(arr, num, maxVarHolder); [/CODE] | |
Re: The first thing you need to observe is "complexity". Intuitively, finding a random number between [0,n] shouldn't be much more complex whether n is smaller or greater than RAND_MAX. So, just a first look at your implementation reveals that something is wrong if the code is so much larger than … | |
Re: I found this quote to be quite nice about your topic: "An abstract function can have no functionality. You're basically saying, any child class MUST give their own version of this method, however it's too general to even try to implement in the parent class. A virtual function, is basically … | |
Re: Basically, if the compiler wanted to inline a recursive function, it would be the equivalent to unrolling a loop. The first rule is that the number of recursions (or loops) has to be determined at compile time. So if your recursive function cannot be turned into a for-loop with a … | |
Re: @firstPerson: read the question: "let's talk about template" and "How do you make this generic?", this is not a OOP or dynamic polymorphism question, but a question on generic programming and template meta-programming. Now to answer the (simple) question: this question is essentially generic programming 101. You can make a … | |
Re: The things between the colon and the curly brace is called the "initialization list". Read this [URL="http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.6"]faq[/URL] on constructors for a good explanation on why this is preferable to assignments inside the body of the constructor. | |
Re: >>is it possible to use mmap for this. Sure it's possible, but is it the best solution? mmap is a general one-size-fits-all solution for large data structures that are paged. It is most likely that your application can take advantage of the structure of your matrix and its usage to … | |
Re: I agree with Ketsuekiame, I don't see any reason why you would "automate" an install of a bunch of software on another computer. Remote desktop to it, or open a secure shell (ssh) to go in and transfer your installation executables (or packages) and run them. It is just as … | |
Re: To turn this into a compilable and runnable program, use this: [CODE] #include <iostream> //this will include the "std::cout" stream for output to console. using namespace std; //this will allow you to avoid writing "std::" all the time. int mystery (int x, double y, char ch) { int u; if … | |
Re: Just read this [URL="http://en.wikipedia.org/wiki/Perfect_number"]wiki[/URL]. There are three easy methods: sum all the number's proper divisors (those with modulus equal to zero) and check if it matches the number; generate one perfect number after another with the given formula until you go beyond the number; check if the bit pattern corresponds … | |
Re: I agree with gerard, the std:: is missing for all uses of string and istream or ostream in the header file. Also, the #include <string.h> should be #include <string> because the former is a C library without std::string. **try to _only_ post the _relevant_ code** | |
Re: There are two functions that are _crucial_ for doing random access into a file stream, that is: tellg and seekg. The first will tell you at what position the reading pointer (g) is at the moment and the second will take that pointer to a previously recorded place (obtained from … | |
Re: You got the curly brackets a bit wrong: [CODE] #include <iostream> //omit the .h for the standard C++ libraries. //#include <stdlib.h> //stdlib.h is a C library that is not really used in C++. class fraction { //start the { just after the class name private: int den, num; //these are … | |
Re: The one problem that I can see is the if you enter a number that is smaller than the first winning number, the search will drive the middle index to 0. And if the 0th value is still bigger than the number entered, "last" will be set to middle-1 which … | |
Re: It is dirty, but it is possible (everything is possible). I have no specific clue to give you but I can give you the basic strategy. First, [URL="http://www.akkadia.org/drepper/dsohowto.pdf"]this[/URL] is an interesting article on dynamic linked libraries (mainly written about Linux's "shared objects" which are the same as DLLs in windows), … | |
Re: **please use code tags in the future** The line "set_terminate(MyQuit);" should have been put inside the main() function. Just move it into main() and it will work. | |
Re: I have never heard of graphics.h, I guess I am too young for that (I only started programming around the time win95 came out, so graphics.h was already outdated!). Here is [URL="http://www.daniweb.com/forums/thread17709.html"]another thread[/URL] with some useful info and links. I can't help any further, it appears you should try something … | |
Hey y'all, I have been working on a tensor library (Nth-order multi-dimensional arrays) and I've been having trouble coming up with a good scheme for a multi-dimensional iterator template. Basically, I have a class template "tensor_container" which stores all the values of the N-order array (as a std::vector of one … | |
Re: First of all, the use of all-upper-case for class names is horrible. By convention, all-upper-case is reserved for #define (or MACROs). If this example was from a book, consider changing book. Now, about your question... first, observe the following: "string" is a class, just like "FLATMATE" is a class. So … | |
Re: I'm assuming you mean a graphical game (like 2D or 3D) because otherwise there is really nothing else you need besides a compiler and reasonable knowledge of C++. For either 2D or 3D, I find that OpenGL is a good place to start and the [URL="http://nehe.gamedev.net"]NeHe[/URL] tutorials are really easy … | |
Re: Yeah, definitely, this is what was expected to happen. The reason why you get so much iterations is because of virtual memory. You said you had 467K available... was that 467M, because if it is only 467K out of 1G, you should think of fixing something because I imagine your … |
The End.