Forum: C++ Jan 16th, 2009 |
| Replies: 5 Views: 1,069 break statements can be used in looping constructs, and in switch/case blocks. They cannot be used to break out of an "if" block, or as an alternative means of returning from a function.
Also,... |
Forum: C++ Jan 15th, 2009 |
| Replies: 4 Views: 297 ::close() just means the function close() is within the global (unnamed) namespace.
In C++, if a function is not explicitly declared with a namespace, it is placed in the global (unnamed)... |
Forum: C++ Jan 15th, 2009 |
| Replies: 4 Views: 297 You're using the function; presumably you can work out which header it came from. close() is not a standard function in C or C++.
I'm guessing it is a function related to sockets handling under... |
Forum: C++ Jan 14th, 2009 |
| Replies: 8 Views: 542 I'd be betting on your side. But that just means he then needs to define the criterion for "The most efficient". For example, does it mean "fastest", "smallest number of machine instructions",... |
Forum: C++ Jan 14th, 2009 |
| Replies: 8 Views: 542 You're developing a realtime application, and don't know how to add values to elements of an array?????
Pull my other leg: it'll play a tune for you.
What is the criterion by which you would... |
Forum: C++ Jan 14th, 2009 |
| Replies: 4 Views: 471 Indeed. 'p' || 'P' would expand to a bool value of true, as will 's' || 'S'. Compilers will generally refuse to compile the above, as particular cases of a switch statement are not allowed to be... |
Forum: C++ Jan 13th, 2009 |
| Replies: 16 Views: 969 Mathematical operations: operators like * (multiplication), + (addition), - (subtraction or negation), / (division), etc.
Splitting up large number and assigning them to an array of ints is one... |
Forum: C++ Jan 13th, 2009 |
| Replies: 16 Views: 969 You can implement a class type that has the attributes you want (or find such a class type that someone else has implemented). Internally, that type might use an array of integers or (as... |
Forum: C++ Jan 12th, 2009 |
| Replies: 7 Views: 715 If n is 1, then the set is {0, 1}.
If you have a set for n, the set for n+1 can be generated by appending a 0 and then a 1 to all elements of the set n.
For example, the set for n = 2 will be... |
Forum: C++ Jan 12th, 2009 |
| Replies: 16 Views: 969 Generally, you cannot. The contents of limits.h generally reflects technical limits on capability of your compiler on your target operating system. Most compilers will need to be... |
Forum: C++ Jan 11th, 2009 |
| Replies: 4 Views: 404 An explicit conversion is what you're calling a cast. An implicit conversion is a conversion between types that the compiler allows or performs, even if you don't do a cast. For example;
... |
Forum: C++ Jan 11th, 2009 |
| Replies: 4 Views: 404 As a general rule, yes you should.
An implicit conversion exists between int and size_t so, in rough terms, you shouldn't need an explicit conversion between them.
Note "explicit conversion" is... |
Forum: C++ Jan 11th, 2009 |
| Replies: 3 Views: 980 Try this. Comments added explaining the reason for change from your code.
#include <iostream> // <iostream> is standard, <iostream.h> is not
#include <cstring> // need functions to... |
Forum: C++ Jan 11th, 2009 |
| Replies: 6 Views: 1,325 You have a description of one possible approach; consider coding it up as an exercise. |
Forum: C++ Jan 11th, 2009 |
| Replies: 6 Views: 1,325 The whole point of Dijkstra's algorithm is to find a least cost (or shortest, in your case) path.
Once you have a first path, eliminate one of the nodes (C2, C5, or C10 in your example) on that... |
Forum: C++ Jan 9th, 2009 |
| Replies: 6 Views: 1,680 My guess is that IMG_GetError() is throwing an exception.
However, it's hard to say, as you haven't provided a complete example. You've paraphrased where your think the problem is.
Try... |
Forum: C++ Jan 9th, 2009 |
| Replies: 3 Views: 2,866 As a matter of fact, your code isn't valid C either. If you are going to ask for help in converting C code to C++, it helps if you post working C code.
You need to read this thread... |
Forum: C++ Jan 5th, 2009 |
| Replies: 11 Views: 640 You're making a distinction that doesn't exist. The Pythagorean Theorem is basic trigonometry. |
Forum: C++ Jan 3rd, 2009 |
| Replies: 3 Views: 804 Firstly, there is no space between the closing bracket at the end of FOR(x,n) and preceding the rest. That's a stylistic concern, but badly hurts readability.
Second, and more significantly,... |
Forum: C++ Jan 1st, 2009 |
| Replies: 6 Views: 1,028 I'd look in the glut header files before looking in the cstdlib. The fact there is even a macro GLUT_BUILDING_LIB to define to "stop a clash between glut and stdlib" says that the incompatibility... |
Forum: C++ Dec 31st, 2008 |
| Replies: 6 Views: 1,028 Of more relevance, try posting a small sample of your code that illustrates the problem. Also provide information about your compiler settings (eg any settings you've tweaked in the VC IDE to... |
Forum: C++ Dec 31st, 2008 |
| Replies: 3 Views: 402 A starting point for you would be to specify what atomic_add_int_nv() actually does under unix. Forum readers are not mind-readers, and not generally all that good at working out what arbitrarily... |
Forum: C++ Dec 31st, 2008 |
| Replies: 5 Views: 492 That's not true. A pure virtual function can be defined (i.e. it can have a function body).
In C++, the "=0" in the declaration is what makes the function pure virtual. In C++, a class with... |
Forum: C++ Dec 31st, 2008 |
| Replies: 5 Views: 805 To give you a clue about what's happening, 100! is about 9.3 by 10^157. To represent that, a 525 bit integer is needed (and that increases 530 bits to represent 101!). 64 bit is nowhere near... |
Forum: C++ Dec 30th, 2008 |
| Replies: 6 Views: 358 You need to be careful with executable compression. Compressed executables have some characteristics associated with self-modifying code (the decompression stub unpacks code and data into memory). ... |
Forum: C++ Dec 30th, 2008 |
| Replies: 6 Views: 358 std::cout and the streaming to it involve functions from the C++ standard library.
As to libraries to use/avoid to minimise executable size, there's no single correct answer. As Salem said, when... |
Forum: C++ Dec 29th, 2008 |
| Replies: 3 Views: 784 If the content of header A relies on content of header B, then it is generally a good idea for header A to #include header B. Examples of "relies on" are;
- header B declares a base class, and... |
Forum: C++ Dec 28th, 2008 |
| Replies: 4 Views: 1,671 The short answer is that you can't. The system() function (it's not a command) supported by win32 compilers/libraries starts up a command shell, and that command shell shows the "black command... |
Forum: C++ Dec 27th, 2008 |
| Replies: 8 Views: 490 Sorry, that statement strikes me as gibberish.
The declaration "static int num;" within the body of class number simply tells the compiler that a single integer named number::num exists somewhere... |
Forum: C++ Dec 27th, 2008 |
| Replies: 15 Views: 2,700 You need to understand the difference between registering a callback function and actually calling it.
Setting TButton's OnClick event egisters a function that will be called when the user -... |
Forum: C++ Dec 27th, 2008 |
| Replies: 8 Views: 490 Narue answered that already.
The "static int num;" within the body of class number declares the static member. The statement outside the class body "int number::num;" defines it.
Declaring a... |
Forum: C++ Dec 27th, 2008 |
| Replies: 8 Views: 490 It doesn't matter where you do it, as long as you obey the one-definition rule (ODR). Typical projects link together object multiple object files to create an executable, and each object file is... |
Forum: C++ Dec 26th, 2008 |
| Replies: 15 Views: 2,700 TButton's constructor needs to be passed a pointer to a TComponent (eg a parent form) that is responsible for managing the button.
It is also necessary to set various attributes: position,... |
Forum: C++ Dec 19th, 2008 |
| Replies: 8 Views: 570 scizj: Look at my previous post. Although I wrote it without having seen your full code, you will find the solution in to your problem within that post. |
Forum: C++ Dec 19th, 2008 |
| Replies: 8 Views: 570 Presumably you have
#include <iostream>
using namespace std;
or something equivalent in the code before your class declaration. The #include directive is needed (if you don't have it, put it... |
Forum: C++ Dec 19th, 2008 |
| Replies: 4 Views: 669 On the first loop iteration, the stream flags are set to defaults. That is not true for subsequent iterations. |
Forum: C++ Dec 19th, 2008 |
| Replies: 4 Views: 669 The short answer is that ios::left and ios::right (and some others) are not mutually exclusive, but your code reflects an assumption that they are. It is possible to have both set simultaneously... |
Forum: C++ Dec 18th, 2008 |
| Replies: 5 Views: 375 Not if efficiency is defined as competence in achieving the intended effect. This is a definition that may be found in english language dictionaries. ;)
But, seriously, ArkM is right: ... |
Forum: C++ Dec 18th, 2008 |
| Replies: 5 Views: 375 I have four concerns with your code, in decreasing order of importance.
1) Your input requires five integers separated by spaces. What do you expect to happen if the user enters 26 27 88 72... |
Forum: C++ Dec 17th, 2008 |
| Replies: 6 Views: 1,282 The only way in which a constructor can report an error is by throwing an exception.
The C++ standard has this to say (in Section 15.2 "Constructors and destructors" which is within Section 15... |