2,898 Posted Topics
Re: >>Is it possible to write a c++ compiler in c++ ? Well, the [URL="http://gcc.gnu.org/wiki/CppConventions"]steering committee of GCC[/URL] believe so. I don't know of any compiler that is entire written in C++, but it is certainly possible. The only problem is that compilers need to be rock solid, meaning that you … | |
Re: What you are describing is just a typical commercial license, with the only difference that you are not charging a price for getting the program (i.e. freeware). But that's still a commercial license, you can charge the price you want for any of the three distributions (app, libs, or source), … | |
Re: Well from the link, the assignment operator requirement is only for "output iterators" where the expression [ICODE]*it = a;[/ICODE] must be valid. BTW, the iterators for the std::set container are not output iterators. So, that shouldn't be a problem. But iterators are not all, you need to watch out for … | |
Re: The main problem, of course, with the code you posted is that the indirect_iterator class implements the assignment operator in terms of an assignment operation on the pointees, not the pointers. Because indirect_iterator was made with the assumption that it should behave exactly as if the iterator was an ordinary … | |
Re: If you make functions that are re-entrant (or almost pure-functional) then you don't have to worry about anything. The main characteristic of a re-entrant function is that it has no dependence whatsoever on data from outside the function (excluding the input variables of course, and read-only access to global (quasi-)constants), … | |
Re: [URL="http://www.cplusplus.com/reference/stl/set/"]std::set[/URL] is a standard container that doesn't allow for duplicates. So, you can just do this: [CODE] #include <set> #include <cstdlib> #include <ctime> int main() { srand((unsigned)time(0)); std::set<int> numbers; while( numbers.size() < 4 ) numbers.insert( rand() % 10 ); return 0; }; [/CODE] | |
Re: You should start by finding the [URL="http://en.wikipedia.org/wiki/Differential_%28infinitesimal%29"]total differential[/URL] of your formula. Then, computing it is a trivial matter with minimal knowledge of C++. | |
Re: You specified your global variable with the keyword "static" which means that the global variable is local to the compilation unit it which it appears (a compilation unit is one compiled .cpp file). This means that the "global" variable Result that appears in "DisplayResult.cpp" is not the same as the … | |
Re: I'm not an expert with boost.spirit, but I don't think that it makes much sense to specify a delimiter which has "any number of spaces" as in the delimiter generator expression [ICODE](*(karma::space) << ',' << *(karma::space))[/ICODE]. This is likely to be the explanation for the infinite loop (probably the star … | |
Re: The problem stems from the fact that you use a very bad integration method for you acceleration. Here are some basics about motion: If [I]p[/I] is the position of an object, and that object is travelling at a constant speed [I]v[/I], then, at time [I]t[/I], the object will be at … | |
Re: >>I know that by default member functions of a class are inlined If member functions are defined within the class declaration, then yes, it is implicitly assumed to have been declared with the [ICODE]inline[/ICODE] keyword. Whether it will be inlined by the compiler is another question that only compiler-vendors can … | |
Re: [CODE] #include <iostream> int main() { for(int i = 0; i < 3; ++i) std::cout << "Ho! "; return 0; }; [/CODE] | |
Re: Here are some good suggestions of algorithms to implement for practice that are a bit more substantive than those suggested already, grouped by topics of scientific computing, most of which are fundamental algorithms that are very relevant in practice too. I also noted rough line-of-code counts (assuming you don't implement … | |
Re: Did you put the glut.h in the "GL" sub-folder of the "include" folder? | |
Re: It all depends on what kind of image processing tasks you need to do. The best place to start is probably [URL="http://opencv.willowgarage.com/wiki/"]OpenCV[/URL]. I'm sure it's possible to at least try to get it working on a DSP (with uCLinux for example). Otherwise, you can at least have access to the … | |
Re: >>By the way, I'm using dark gdk which has some simple collision detection tools by itself. though when i use the code to detect collision for objects, the program just skips over it without doing any thing. it doesn't even any errors. I suggest you review the documentation on dark … | |
Re: 1) If you are not going to put anything in DllMain than you might as well remove it. 2) It seems you have made your DLL compatible with C, or at least, tried. If you really want compatibility with C, you cannot use references. If you will always compile the … | |
Re: It seems to me that this piece of code is suspicious, in the "highlight" function, towards the end, you have: [CODE] char *temp=new char[len(text)+108]; sprintf(temp,"<table width=\"100%%\" border=\"0\" cellspacing=\"0\">\n<tr>\n<td>1.</td>\n<td bgcolor=\"#FFFFFF\">%s</span></td>\n</tr>\n</table>",text); [/CODE] I counted 116 additional characters (considering the newlines to be one character, which is not the case on all OSes). … | |
| |
Re: Well, the line "getch();" is going to wait for the user to type a character before exiting the program. Remove it and the program will exit after printing "End of file!" and the console window will close. | |
Re: In a similar fashion as gusano79 has suggested, you can use a templated wrapper to reduce the amount of coding necessary for the different wrappers. Here is what I mean: [CODE] class Airplane { public: virtual void fly() = 0; virtual void speed_up() = 0; }; template <typename AirplaneType, void … | |
Re: You should remove the [ICODE]Shape::[/ICODE] in front of each function name within the declaration of the Circle or Triangle classes, you don't need that and should have it there (and that's the error your compiler reports). | |
Re: The prototype of displayGame needs to match its definition _exactly_. So you need this prototype instead (at the beginning): [CODE] void displayGame(Game[], int); [/CODE] | |
Re: >> Would the last line work? No. >> Or do I have to declare a vareable to do any math/calculations? Yes, you can do computations to obtain the initialization value of a global variable, but you cannot do general statements. >> Does it execute in a top down fashion? Yes, … | |
Re: Quick answer: remove the [ICODE]template <class T>[/ICODE] on lines 59 and 67. Long answer: The problem here is that you are defining, in the general class template, two function template (operators << and >>). Then, in the specialization, you define a friend function. For a moment, forget the whole business … | |
Re: Why not use an embedded accessor class: [CODE] class PersonalInfo { private: int ID; string Name; public: struct Accessor { int& ID; string& Name; Accessor(PersonalInfo& Host) : ID(Host.ID), Name(Host.Name) { }; }; struct constAccessor { const int& ID; const string& Name; constAccessor(const PersonalInfo& Host) : ID(Host.ID), Name(Host.Name) { }; }; … | |
Re: First of all, the loading of the texture and the registering of it to OpenGL only has to occur once. So, you should move the call to LoadGLTextures() to the init function. All that you need to do before you render the polygons on which the texture is applied is … | |
Re: Well, of course, AD and firstPerson's answers clearly doesn't do what you want. vijayan121's answer is probably as much as you'll be able to do, that is, make the return type into whatever type that is common to both operand types. Which, again, isn't exactly what you want. And, in … | |
Re: If you use the clock() function, it will return the clock ticks elapsed by your process only. My guess is that you have been using a general local-time function like "time()" to measure your elapsed times. The time() function and the clock() function are fundamentally different in the sense that … | |
Re: Hi woody363, To install Qt, you can simply install qt-creator (the main IDE for Qt). Here are the detailed instruction to install that: 1) Go to a terminal window. 2) Type this (the dollar sign not included): [CODE] $ sudo apt-get install qtcreator qtcreator-doc [/CODE] 3) Enjoy (the Qt Creator … | |
Re: Boost.Spirit should be used. Boost.Spirit is the library that allows you to create a grammar and do parsing / generation of XML data. The purpose of Boost.Serialization is very different, it is true that it can interact with XML to do the serialiation / unserialization, but it isn't a parsing … | |
Re: To add to vijayan121's great explanation. Although nice, the <chrono> header doesn't solve the problem of the epoch of reference, it is still implementation-defined, which is a good thing in general, but a problem, of course, if you want some type of absolute reference. The [URL="http://www.boost.org/doc/libs/1_48_0/doc/html/date_time.html"]Boost.Date-Time[/URL] library is a good … | |
Re: >>The compiler plainly doesn't allow this. Basically, the restriction that is imposed on the default arguments (for function parameters) is that they cannot be derived from or referring to the other function parameters. And because the "this" pointer is a hidden first argument to any class member function, any non-static … | |
Re: >> The above code (on the GCC compiler) creates the problem where TestB doesn't actually call TestB's constructor, I does call the TestB constructor, just not the one you defined but the default, compiler-generated copy-constructor. If you don't provide a constructor of the form [ICODE]TestB(const TextB&)[/ICODE], the compiler will generate … | |
Re: >> What are ostream & istream and what do they do? ostream stands for output stream, and istream stands for input stream. They are base classes that define the interface for any input/output stream. All the stream objects in the C++ standard library derive from one of these base classes … | |
Re: What you are describing is a build script, that is what you need. Personally, I am not familiar with Visual C++'s build system and the possibilities it offers to write build scripts. The main reason I'm not familiar with it is because it generally sucks and most large cross-platform projects … | |
Re: Well. Maybe WaltP has 1 in 50 chance of finding the error, but I have an eagle eye and a compiler built into my brain, which means I have a 100% chance of finding the error. And the error is at this line in your loop: [CODE] sum1++=p; [/CODE] You … | |
Re: The Boost.MPL is a great tool for template meta-programming. It basically contains an entire compile-time implementation of the STL containers and algorithms. So, yes, there are plenty of alternatives to loki::Typelist. In MPL terms, these are [URL="http://www.boost.org/doc/libs/1_47_0/libs/mpl/doc/refmanual/sequences.html"]Sequences[/URL]. You can choose, like with STL containers, whether you want random-access or not, … | |
Re: Sure. The important thing is that you make sure that both have the same calling convention. If your DLL function was compiled with another calling convention, then that's the calling convention that you should have for your function-pointer type "pICFUNC". BTW, the default calling convention in C/C++ is "__cdecl" on … | |
Re: >> I've been Programming in C++ for a year. I am done with Basics and all other OOP concepts(like inheritance,polymorphism and STL) That's funny. I've probably said that (i.e. "I am done with ... ") every year since I started programming (13 years ago or so), but it was always … | |
Re: If you want to stick to C++, and remain cross-platform, I would just suggest you use [URL="http://qwt.sourceforge.net/"]Qwt[/URL] (add-on to Qt). The image on their home-page is a Bode plot, so I'm pretty sure you can use that library for your purpose. If you don't absolutely need C++, then Matlab or … | |
Re: Whenever you provide default parameters for a function (whether a constructor or otherwise) they should appear in the declaration of the function, not in its definition. In other words, your constructor declaration (in header file) should be: [CODE] public: Person(string first = "", string second = ""); [/CODE] And your … | |
Re: It is quite intriguing indeed. Maybe you should try to also print out the counts on the allocate calls. So far, I don't know what would cause the double allocate, especially since it doesn't match the number of deallocate calls, that is even more disturbing in my opinion (I say … | |
Re: Simple typo: [CODE] if (r=y && c==x){ [/CODE] should be: [CODE] if (r == y && c == x){ [/CODE] (notice the double = signs. **Please use code-tags in the future. | |
Re: >>What is the point of a static method? The point of a static method is that it can access all the private members of the class but isn't tied to an object (instance of the class). I would agree that it isn't the most useful thing in the world. One … | |
Re: First of all, I don't know if the implementation of "Matrix" class is special, but normally, in C/C++, the indices (i,j) go from 0 to N-1, not from 1 to N (like in Matlab or Fortran). If this Matrix class is implemented to handled 1-based indices, then I highly recommend … | |
Re: First of all, [URL="http://www.daniweb.com/software-development/cpp/threads/391439/1686649"]this thread[/URL] should answer all your questions about what a DLL is and what is meant by "dynamic-link". Now, for a simple example of a DLL, here is the simplest example I can think of, the "hello world" program: In hello_world.h: [CODE] #ifndef HELLO_WORLD_H #define HELLO_WORLD_H #ifdef … | |
Re: >>care to expand? I tend to think of data hiding as a likely consequence of encapsulation. In a similar sense that encapsulation is the bundling of data and behaviour in a single entity, I usually also attach to that the presence of some form of hiding the details (like the … | |
Re: First, the obvious, in both cases, you have compiled code, so it is all a matter of linking and loading. In all cases, a .lib file is a static-link library, meaning that it is used by the linker to complete all the function calls that exist in your application that … | |
Re: You can simply store your objects in a vector, that is, you can do: [CODE] #include <iostream> #include <string> #include <vector> using namespace std; class record { public: string name; string bankAccountNum; double accountBalance; void output(); }; int main() { //create a vector container of customers: vector<record> customers; record customer; … |
The End.