2,898 Posted Topics

Member Avatar for Labdabeta

>>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" …

Member Avatar for mike_2000_17
0
226
Member Avatar for montjoile

>>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 …

Member Avatar for Duoas
0
280
Member Avatar for vanalex

>>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 …

Member Avatar for vanalex
0
112
Member Avatar for Haranadh

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 …

Member Avatar for mike_2000_17
0
312
Member Avatar for IMJS

> 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, …

Member Avatar for mrnutty
0
187
Member Avatar for FoxInBoots

[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 …

Member Avatar for FoxInBoots
0
162
Member Avatar for yashsaxena

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 …

Member Avatar for yashsaxena
0
4K
Member Avatar for dgreene1210

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 …

Member Avatar for dgreene1210
0
265
Member Avatar for annitaz

>>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 …

Member Avatar for annitaz
0
199
Member Avatar for Labdabeta

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]

Member Avatar for ddanbe
0
351
Member Avatar for mattloto

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 …

Member Avatar for mike_2000_17
0
137
Member Avatar for ravenous

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()); …

Member Avatar for Narue
1
2K
Member Avatar for Smartflight

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. …

Member Avatar for mike_2000_17
0
118
Member Avatar for ocramferreira

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, …

Member Avatar for iamthwee
0
572
Member Avatar for n0de

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". …

Member Avatar for mike_2000_17
0
94
Member Avatar for eman 22

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; …

Member Avatar for mike_2000_17
0
341
Member Avatar for eman 22

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 …

Member Avatar for mike_2000_17
0
86
Member Avatar for Vivek0909

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 …

Member Avatar for mike_2000_17
0
237
Member Avatar for andylbh

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 …

Member Avatar for mike_2000_17
0
789
Member Avatar for MixedCoder

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 …

Member Avatar for mike_2000_17
0
438
Member Avatar for andylbh

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 …

Member Avatar for andylbh
0
705
Member Avatar for Danny1994

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).

Member Avatar for andyman2
0
147
Member Avatar for stereomatching

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 …

Member Avatar for thekashyap
0
162
Member Avatar for jayrpalanas

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 …

Member Avatar for iamthwee
0
171
Member Avatar for EEETQ

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), …

Member Avatar for NicAx64
0
230
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
203
Member Avatar for Jsplinter

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 …

Member Avatar for Jsplinter
0
258
Member Avatar for chintan_1671
Member Avatar for thekashyap
0
1K
Member Avatar for thekashyap

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 …

Member Avatar for thekashyap
3
580
Member Avatar for UltimateKnight

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 …

Member Avatar for UltimateKnight
0
160
Member Avatar for goocreations

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 …

Member Avatar for rubberman
0
143
Member Avatar for Jsplinter

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 …

Member Avatar for mike_2000_17
0
4K
Member Avatar for jimmymack

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 …

Member Avatar for jimmymack
0
134
Member Avatar for jimmymack

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 …

Member Avatar for jimmymack
0
142
Member Avatar for dadam88

>>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 …

Member Avatar for dadam88
0
200
Member Avatar for wildplace

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 …

Member Avatar for mike_2000_17
0
222
Member Avatar for jimmymack

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 …

Member Avatar for jimmymack
0
137
Member Avatar for Saith

>>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 …

Member Avatar for vijayan121
0
307
Member Avatar for munitjsr2

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 …

Member Avatar for mike_2000_17
0
2K
Member Avatar for Sonia11

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) …

Member Avatar for mike_2000_17
0
174
Member Avatar for Rocker Gang

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 …

Member Avatar for mike_2000_17
0
156
Member Avatar for Mr. K

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 …

Member Avatar for Mr. K
0
117
Member Avatar for Labdabeta

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 …

Member Avatar for mrnutty
0
638
Member Avatar for jimmymack

Take out line 71. It is probably a left-over, and it is not needed (and is, of course, the erroneous line).

Member Avatar for jimmymack
0
154
Member Avatar for ankit.4aug

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 …

Member Avatar for Tellalca
0
798
Member Avatar for choboja621

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 …

Member Avatar for Narue
0
130
Member Avatar for bkoper16

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 …

Member Avatar for Chilton
0
110
Member Avatar for stkarnivor

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 …

Member Avatar for mike_2000_17
0
582
Member Avatar for n0de

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 …

Member Avatar for n0de
0
1K
Member Avatar for geekme

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 …

Member Avatar for mike_2000_17
0
584

The End.