2,898 Posted Topics
Re: >>Does anybody know what is causing the colour mix up? The pixel transfer/storage. Clearly, the image is correctly loaded from the file (since you can see an undistorted NeHe icon). The problem must be with the format of the BITMAP image. I would guess that your format "GL_BGR_EXT" and "GL_UNSIGNED_BYTE" … | |
Re: >>what is a namespace A namespace is literally a "name-space". When programming large libraries, you need names for everything (e.g. data-types, variables, constants, classes, functions, parameters, etc., etc.). How do you make sure that the names that you pick will not conflict (or "clash") with other names in other libraries … | |
Re: >>When we use a table's name as a parameter the table is used as an address (the address of its first element) Correct. >>then &tab is a pointer to tab's first element address? Correct. &tab is a pointer to the pointer to the first element in the table. >>What does … | |
Re: First things first, don't store matrices as arrays of arrays. You need to store them contiguously, i.e., you make one big linear array and store either one column after another (column-major) or one row after another (row-major). Storing arrays of arrays is very inefficient in general. Second, save yourself the … | |
Re: > Was I right in believe that thisMyClass was out of scope in myFunction()? No, the object was created before the function call and gets deleted after the function returns. So, unless your myFunction() does something unholy, the passed object is in scope and the pointer is valid. Of course, … | |
Re: [ICODE]void[/ICODE]: is a type that acts as a place-holder for "nothing". >>I don't understand where you get the value for "A", "C" or "rad" when it's not given a value anywhere in the code. "A" "C" and "rad" are function parameters. A declaration like [ICODE]float add(float a, float b);[/ICODE] declares … | |
Re: Narue's answer is good, of course. But on a less formal basis, I see encapsulation and abstraction as sort of two sides of the same coin. In both cases, you usually hide away the details that the user of your library or class doesn't need to know about (hiding data … | |
Re: You misplaced the parentheses on your print line. It should be: [CODE] printf("((%d / %d) + %d) * %d is %d\n\n", num1, num2, num3, num4, result); //notice ) at the end and not after the last \n". [/CODE] If you are wondering why your code still compiled with the misplaced … | |
Re: >>Are my answers correct? Not quite. Without giving anything away.. a) Think a bit more about what happens at "step 4: fix(q1, 2-1)". This is a recursive call (a function calling itself again, usually with different parameters, in this case, n-1 instead of n). b) Already, with your current answer … | |
Re: An unsigned char is just a regular unsigned integer going from 0 to 255. Just interpret it as a regular "number" and map 0 to -1.0 and 255 to 1.0 with a simple linear mapping: [CODE] unsigned char u; float f; f = float(u) / 127.5 - 1.0; [/CODE] | |
Re: As for data structuring for this, you can use polymorphism, in which case you have to look for what is common to all things involved. In this case, I would suggest at least one function: "evaluate()". All expressions or values have to be able to be evaluated to yield a … | |
Re: I agree, the OP's solution is better than the others posted. The remove_if is exactly meant for this purpose and it's use is clear, efficient and idiomatic. But the string copying is useless btw, the idiomatic use of remove_if is as follows: [CODE] myString.erase( std::remove_if( myString.begin(), myString.end(), isspace ), myString.end()); … | |
![]() | Re: Generally, to be safe, you implement these kinds of "instance counters" wrapped in a factory function. Typically, you also don't want spurious copies and things to be created, so you make the class non-copyable. This way you count only the "uniquely new" objects that were created, not copies and temporaries. … |
Re: As suggested already, you should store all the strings from the file into a set. Now, you can choose: - std::set: Uses a balanced-tree implementation to sort and search for words. Most operations are O(logN) time. - std::unordered_set: This is going to be part of C++ standard library very soon, … ![]() | |
Re: std::vector 101: (for vector v) - Use v[ index ] to read or write any value at "index" position. - Use v.begin() and v.end() to get an iterator at the beginning or end of v. - Use v.resize( newSize ) to change the number of elements in v to "newSize". … | |
Re: Of course, follow Narue's advice, she's always right! But, just to add to it: You will have to specify the type for the use of the class template in your other class template: [CODE] #pragma once template<typename T> class D; //remove the <T> template<typename T> class B { D<T>* d; … | |
Re: Basically, the rule goes like this: - A forward-declaration of a class is sufficient to create and use a variable whose type is a pointer/ref to that class. - A class declaration is required to create or use a variable whose type is of that class (value). When you dereference … | |
Re: Intuitively, I would guess that the problem is that you are attempting to close a file stream that was never opened or already closed (i.e. Stream == NULL causes the assertion failure during the closing of the file, in fclose()). The ZeroMemory() part seems suspect too. In C++, it rarely … | |
![]() | Re: The sort algorithm (or the std::set container) have an optional parameter which is the Compare function for the elements to be sorted. This comparison function is, by default, the less-than operator which ends up sorting things in increasing order. You simply need to make a functor (callable object) which does … |
Re: The error message says it all. You have made the function OnConnected() a pure virtual function which means that it has no implementation in the class Connection, which, in turn, forces you to provide a class, derived from Connection, that implements this function. In short, this pure virtual function makes … | |
![]() | Re: The easiest solution is surely to use simple print() functions instead of overloads, as follows: [CODE] //in the header: class Point2D { //... void print(ostream& out, bool WithDistFrOrigin = false) const; }; //in the .cpp file: void Point2D::print(ostream& out, bool WithDistFrOrigin) const { out << "[" << setw(4) << p2d.x … ![]() |
Re: I don't know of any, I don't do .Net at all. But I just wanted to point out that what you seem to be looking for is called an "obfuscator". Search ".Net Dll obfuscator", you will find plenty (free and not free). | |
Re: Yes, you can do so. But, of course, not using "dynamic polymorphism" but "static polymorphism" (as in, at compile-time). In your example, you don't need dynamic polymorphism, so it will work (when you really do need it, it won't). The basis for achieving this is via a clever technique called … | |
Re: Windows or Linux? (or Mac?) Try [URL="http://www.codeblocks.org/downloads/26"]CodeBlocks[/URL] (for windows, make sure you download the one with mingw (the compiler)). For Linux, just ask your package manager system! For the compiler: 'build-essentials'. For a good IDE, either 'codeblocks' or 'kdevelop' (I prefer the latter). All these are based on the GCC … ![]() | |
Re: The error is obvious. At line 197, you use a local variable called "books" to record the booksBorrowed. Then, you insert into your std::map a value which is the address to that local variable. Then, you return from that function, which also causes that local variable to disappear (be destroyed), … | |
Re: You should play around with the pixelformatdescriptor. This is often a source of weird errors because when it cannot be realized, the OS chooses a closely matching pfd and sometimes that pfd is crap and gives very weird results. What parameters did you try? Most modern computers work on a … | |
Re: You have indeed a simple problem of terminology. What you are describing is a classic problem in, at least, the fields of machine learning and data mining. The problem is called "data clustering" (which is part of the field of "unsupervised learning methods" for "data classification"). If you search for … | |
Re: Your function needs to return a LRESULT, not void. And your parameters are inverted | |
Re: Nice explanation, but I do have a few things to point out. First, a few details. You make extensive use of variable names, defines and identifiers which start with an underscore character. This is explicitly forbidden by the C++ standard. All identifiers starting with one or two underscore characters are … | |
Re: conio.h is a non-standard library for MS-DOS. You can read the little [URL="http://en.wikipedia.org/wiki/Conio.h"]wiki[/URL] on it. The only function that requires conio.h in that piece of code is the final statement getch() whose sole purpose is to pause the program until you press a key. First of all, you should definitely … | |
Re: well I know that the last delete statement you have should be an array deletion, as such: [CODE] delete[] c; [/CODE] But other than that, I don't see any reason for the "weird" behavior. It might simply be that your implementation (compiler + libs + OS) has a more sophisticated … | |
Re: D) Use Boost.Multi-Index. This is a library for keeping an array sorted according to multiple indices (i.e. keys). This is probably the best and easiest way to keep the list "sorted" according to both the key and the value at the same time. However, if you just want to completely … | |
Re: I think you are stepping into this topic a bit too early in your learning experience. To understand it, you should read [URL="http://www.parashift.com/c++-faq/multiple-inheritance.html#faq-25.12"]this FAQ[/URL]. And I would also suggest you first read all the parashift FAQs that come before as well (chapters 0 to 25). >>theName is passed to the … | |
Re: You got this example from "Teach yourself C++ in 21 days". Do you really think that is possible? [URL="http://norvig.com/21-days.html"]Really?[/URL] By seeing the quality of the code in this simple, short example, it doesn't baud well for the remainder of the book. Anyways, I think Saith covered what was needed. You … | |
Re: >>When I do have a condition to set the loop = 0 (false), my loop continues to run though! There are two keywords you need to know about: [ICODE]break[/ICODE]: this instruction will terminate the loop. In other words, the execution "jumps" from where the 'break' statement appears to the line … | |
Re: dist: This is an array that stores the estimate of the distance to the source (through the "optimal" path) for every vertex in the graph. This is a quantity you want to minimize all the time, i.e., this is a shortest-path algorithm. previous: This is an array that stores, for … | |
Re: Ok, in your second last post, you are right! That is exactly how it goes. As for 'theName', there are two of them. Both are inherited from Person, but one is inherited through Student and the other is inherited through Teacher. This is why you can access one via Student::theName … | |
Re: >>hoping <enter> would made an eof approach Yeah, cin is special, it basically never has an end, because it can always wait for the user to input more stuff. But, in any case, that kind of while(some_stream >> value) loop is pretty usual for other "normal" streams (like file streams … | |
Re: As L7Sqr said. And, of course, since find_if/find only finds the first occurrence, it is a trivial matter to wrap it in a while loop to find all the occurrences: [CODE] int main() { std::vector<int> v; //populate v. Now, delete all 0 values: std::vector<int>::iterator vit = v.begin(); do { vit … | |
Re: You need to post more code, that's for sure. If it is too big, just make a copy of it all, then strip away as much as you can without eliminating the error (unless you find the bug!), then post it. Also, try this: [CODE] void candidateType::setVotes(int region, int votes) … | |
Re: For polymorphic types, it is quite easy to imagine (for a lack of actual knowledge). The compiler generates a static const type_info structure for each type that appears in the code. Then, if the type already has a virtual table (has at least one virtual function), then an entry is … | |
Re: I doubt that using difftime with clock_t is a good idea. difftime works with data of type time_t, which is obtained from the function time(). The clock() function returns clock ticks since the start of the program, and if I'm not mistaken, the clock ticks are only those counted towards … | |
Re: First of all, [ICODE]if(x==MINVAL)[/ICODE] makes no sense, I think you meant to write [ICODE]if(x < MINVAL)[/ICODE]. Second, I'm pretty certain that you would be better off using a Tailor series expansion. All you should need is a Taylor series expansion around 0 degrees for both the sine and cosine, which … | |
Re: Take out line 71. It is probably a left-over, and it is not needed (and is, of course, the erroneous line). | |
Re: First of all, what you are referring to is called "pass-by-reference" and "pass-by-pointer" because it pertains to the passing of the parameters to a function, not to the calling of the function. Those who use those "call-by-" terms are simply sloppy with their terminology. Their are two main purposes for … | |
Re: To flush the standard output, you can do [ICODE]std::cout.flush();[/ICODE]. As for the input buffer, you can't really flush it, but usually either [ICODE]std::cin.ignore();[/ICODE], [ICODE]std::cin.clear();[/ICODE] or [ICODE]std::cin.sync();[/ICODE] will achieve what you want (i.e. ignore stray characters, clear error states, or re-synchronize with the buffer). Try those. I don't really know about … | |
Re: In order to be able to print using << with a custom type (class), you need to overload the << operator of the std::ostream class. And since you are using some class inheritance, it is probably advisable to use a virtual print() function for printing the content of your class … | |
Re: Typedefs are just aliases, they don't "create a new type". So, you have to overload the operator for the underlying type. You can also overload with the typedef, but that will just overload for the underlying type as well. So, basically, the rule applies as for the underlying type. If … | |
Re: Narue is correct, of course. With, maybe, the additional remark that if you are going to make a copy of the parameters immediately as you enter the function, you are better off passing-by-value instead, you get a local copy, and you allow the compiler more opportunity for optimizations. Furthermore, operators … | |
Re: All you need to do, since BGL is a header-only library, is to add the include directory for boost in your CB project. First, of course, you need to have installed Boost libraries, by following the instructions on the [url]www.boost.org[/url] Getting Started page. After that, you should have boost installed … |
The End.