1,296 Posted Topics
Re: Alas, do not use all stilllearning's methods (sorry, stilllearning ;)). The safe method: [code=cplusplus] std::string foo(.......) { // not string& !!! char buf[...]; // form buf contents return buf; // don't worry: it returns string object } // or if you don't know max buf size std::string bar(.....) { std::string … | |
Re: To all appearances you are trying to reinvent std::valarray class ;). Look at <valarray> header of your C++ installation. For example, in MS VC++ 9 you can see: [code=cplusplus] template<class _Ty> class valarray { // store array with various indexing options ... valarray<_Ty> operator+() const { // return +valarray _VALOP(_Ty, … | |
Re: Hmm, hex manipulator on the C language forum... Be afraid of pure C fanatics ;)... | |
Re: Of course, the C++ compiler does not like overloaded shift operator with string left operand. You want [icode]insert >> word[/icode], right? A very unfortunate name for input stringstream: insert... | |
Re: What's a wonderful nightmare code! ;).. Log10 denotes decimal (base10) logarithm. Obviously, you want [code=c] log((double)INT_MAX)/log(2.0) + 1 [/code] | |
Re: I think it's a very interesting question. From the C++ Standard (4.5, 1): [quote]An rvalue of type char, signed char, unsigned char, short int, or unsigned short int can be converted to an rvalue of type int if int can represent all the values of the source type; otherwise, the … | |
Re: Yet another wrong code fragment: [code=cplusplus] #define ROWS 2 #define COLUMNS 2 ... for (i=0; i<3; i++) { // *** < 2 or better < ROWS for(j=0; i<3; i++) // *** j++ !!!; // *** < 2 or better < COLUMNS cout << Screen_Array[i][j]; } [/code] | |
Re: You try to get tax_rate with wrong format specifier (%d used only for int values but your tax_rate is float). Must be: [code=c] scanf("%f", &tax_rate); [/code] Better use double type for all your numbers. Don't forget that input format specifier for double is %lf, not %f. | |
Re: Sacramental phrase: Google is your friend... [url]http://support.microsoft.com/kb/828736[/url] | |
Re: Non-static member function always called for the object, not in itself. The glutMouseFunc does not know, which object used for member function call. So it's no sense to pass a member function pointer to glutMouseFunc: it can't use such a pointer. In other words, a pointer to a function is … | |
Re: What is meant by pseudo-eof? If it's EOF macros from C stdio.h header then it's not a char value, it's int type value returned by stream input functions. So this EOF is not a char from the file (and no problems with 8-bit or 16-bit values at all). Take into … | |
Re: [quote]The txt file has numbers and the only way i can put them into an array is to put them into a char array.[/quote] Why?!.. Do you know that unsigned char range is 0..255 only? [quote]the numbers in the txt file are as long as 10,000 per line. The char … | |
Re: Probably you forget to start your main function from its header int main(): [code=cplusplus] #include <iostream> using namespace std; int num; int main() // ????????????? { [/code] ;) Why int num declared on global level?.. | |
Re: Sorry, but parameter [icode] string array[100][/icode] is equivalent of pointer to array of strings passing, so it's correct way to go... | |
Re: Yet another prompting: X(1) + X(2) + ... +X(n)+... X(1) = x X(n) = (+/-)x*x*...n times / (1*2*...*(n-1)*n) = (-x/n) * X(n-1) It's so simple ;)... | |
Re: 1. In C++ we must declare all names before using. From the C++ Standard: [quote]Declarations specify how names are to be interpreted.[/quote] Function prototype is the most common form of function name declaration. Function header + function body called function definition. A definition is a declaration too. So you must … | |
Re: Well, and what's your problem? [code=cplusplus] Contact todo("Please","look@your.textbook","12345"); todo.print(); [/code] Is it a problem? | |
Re: Another way to correct situation: make help(), quit(), finished and action_index members static. In that case you can add pointers to help and quit functions to action_index map. Pointers to static member functions are the same as usual pointers. | |
Re: Some remarks. String handling per se is a smallest part of a scanner - the simplest component of any compiler. No problems to implement effective scanners in C or C++. Syntax parsers and code generators (main parts of compilers) work with internal data structures and does not take trouble over … | |
Re: If you have (void*) pointer p to byte-addressable memory then you can add byte offset A0 to it with a very simple expression: [code=c] p = (char*)p + 0xA0; [/code] Dirty job, eh?.. | |
Re: Let pnode is a pointer to a DLL_node. Now [code=cplusplus] pnode->contact->print(); [/code] prints this node. Can you write the code traversed linked lists from the head to the tail? Is it your "problem behind problem"? | |
Re: You are looking for a deep copy silver bullet but your compiler does not know the semantics of this operation for your classes. YOU know the semantics. That's why user-defined copy constructor and overloaded assignment operator were invented in C++. It's a matter of the right object model design. For … | |
Re: It's not an optimizing compiler, it's a linker does it! That's why static libs were invented many many years ago ;)... | |
Re: It's absolutely senseless statement in C++: [code=cplusplus] char message[] = the_date[12]; [/code] You try to declare an array of unknown size, so you must provide brace-enclosed initializer-list with constant initializers or string literal (see declaration of oldname), but the_date[12] in this context denotes non-existing 13-th element of the_date array (it's … | |
Re: It seems this function had its Fortran prototype, so indicies started from 1 to N (and right corrected dimension bound N+1): typical ad hoc porting solution. Better give us a reference to this alg method and source (present data file contents too). I have some doubts about the algorithm. It … | |
Re: See, for example: [url]http://en.wikipedia.org/wiki/Virtual_function[/url] [url]http://www.codersource.net/cpp_virtual_functions.html[/url] | |
Re: Let one (anyone) client is appointed "p2p server" and another client is appointed "p2p client" by the server. [quote]I can write the program that let server and client connect[/quote] That's all - you know the right solution. After p2p connection establishing they will have only p2p protocol troubles as was … | |
Re: Never use a very expensive pow() function in this context. You want to change subexpression sign for odd p only. Make it explicitly, it's much more faster code: [code=cplusplus] temp = b[0][p]*determinant(c,m-1); if ((p&1) != 0) sum -= temp; else sum += temp; return sum; [/code] or, may be [code=cplusplus] … | |
Re: Yes, it's the simple truth but not the complete truth, see also [url]http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx[/url] ;) | |
Re: All C compilers create all arrays as 1D arrays: the C language defines a strict mapping of multi-dimentional array to contiguous 1D array... | |
Re: 1. Regrettably, for negative numbers williamhemsworth's solution does not work (moreover, gives wrong result - for example, it yields 0 for -0.9 but nearest integer value for -0.9 is -1). Right solution: [code=cplusplus] #include <cmath> ... double round(double x) { bool negative = false; if (x < 0.0) { x … | |
Re: In addition, operator= sceleton should be: [code=cplusplus] ThreeD& operator=(const ThreeD& op2) { if (this != &op2) { .... } return *this; } [/code] | |
Re: May be better ask on 7-Zip forum? [url]http://sourceforge.net/forum/forum.php?forum_id=45797[/url] | |
Re: Generally speaking getch() is not "Borland specific". It's a function declared in <conio.h> - commonly used and partially supported but not standardized console input/output header. Sometimes its name is _getch() but as usually in that case conio.h includes macros for "deprecated" getch. It's impossible to inplement full getch() functionality with … | |
Re: Regrettably, I do not know who was the 1st author of the printf source. There are many implementations of printf. Google search for "printf source code" returns lots of links, for example: [url]http://www.menie.org/georges/embedded/index.html#printf[/url] [url]http://www.sparetimelabs.com/tinyprintf/index.html[/url] etc... You may download GNU clib sources or buy Visual Studio with RTL sources. Write your … | |
Re: On the codeguru forum author of SynchronizedQueue wrote to his correspondent: [quote]Do you have any experience in c++ programming? the reason I'm asking is because it's crucial to applying the scheme I've supplied before.[/quote] The same question to you?.. | |
Re: 1. Add #include <string> 2. Add [code=cplusplus] string path; ...// get dir name into buf then path = buf; path += "System\\Unreal.exe"; // Now you have string path with // "F:\Tolvuleikir\Full\FPS\Unreal Anthology\UnrealGold\System\Unreal.exe" system(path.c_str()); // Start the application [/code] 3. Don't muddle double backslashes in source text literals with "friendly executable … | |
Re: 1. You forget semicolon after if statement: [code=cplusplus] if (*p) p++; // *** *q = '\0'; [/code] 2. Use code tag for your snippets on this forum: [noparse][code=cplusplus] your code [/code][/noparse] 3. Make a proper source code indentation. You write C++ programs, not adult's graffiti... | |
Re: I think the right solution is std::map<std::string,int> (another name of map is dictionary). Fast search, automatic sorting + Ancient Dragon's counter - three in one solution. | |
Re: No compiler error when you compile THIS code with Object and Pont declarations only. Of course, you can't create this class Point object because of it does not implement all Object interaface and therefore it is an abstract class too. Let's start from the class Object redesign: 1. The setCoords() … | |
Re: I don't know why but merge_sort function in attached file is a senseless text in unknown language (it's not C and C++). Look at the correct merge sort implementation in C++: [url]http://www.algorithmist.com/index.php/Merge_sort[/url] [url]http://www.algorithmist.com/index.php/Merge_sort.cpp[/url] May be it helps... | |
Re: As far as I know flag/lock file method works on all platforms. See discussion on this topic: [url]http://www.velocityreviews.com/forums/t137115-preventing-multiple-instance-standalone-desktop-gui-applications.html[/url] | |
Re: Bresenhamn's optimized algorithm initializes deltax, deltay and error AFTER swappings. Your program initializes them BEFORE swappings. Why?.. | |
Re: It seems you don't understand basics of dynamic memory allocation: 1. struct node has char*name member (pointer to char) but you don't allocate memory for name object. So you have garbage pointer values in uninitialized structures. Use malloc to allocate memory and save pointers to these structure members for all … | |
Re: 1. Use code tag to present your snippets: [noparse][code=cplusplus] your code [/code][/noparse] 2. Stop this terrible source alignment! Use indentation. 3. You declare uninitialized pointer to substr class object (s). But where is the object? 4. Your substr class contains the only (and very dangerous) member function. It's a very … ![]() | |
Re: Stricktly speaking it's possible and valid behaviour of floating-point calculations. Floating point types are not mathematical real numbers. The last ones have "infinit" precision but doubles and floats are approximations of real numbers. So C language literal 0.7 is an approximation (of double type by definition) of the real number … | |
Re: There are lots of undeclared identifiers in your snippet. May be better post the source after you (and me) can compile it w/o errors? | |
Re: It seems you have much more problems, for example: [code=cplusplus] base crash(0); // why not? [/code] How about strlen(0) in your constructor? Yet another example: [code=cplusplus] { base bomb; // Default constructor do not initialize name member! ... } // Bang! Dectructor delete something via non-initialized pointer... [/code] How to … | |
Re: What data structures you consider Advanced? Try to implement a very fast (and huge) priority queue with erase by key operation... | |
Re: Compile your project in VC++ 2008 as a console (not Forms) application and you will get the same result as in Code::Blocks (probably, your Code::Blocks IDE used VC++ to make console application)... |
The End.