1,296 Posted Topics
Re: 1. The AverageNum function (incorrect, see #2 below) has a side effect: the input stream is in eof (or failed) state after this function call. You din't correct this state: din't close stream, din't rewind (reset read pointer) it - do nothing. After absolutely senseless 1st call in B choice … | |
Re: In short: no, it's impossible to extract filename used in open file stream call from a stream object. It's a long story why... In actual fact fstream object passed this name to filebuf object and works with this internal object which provides/consumes data. Moreover, it's possible to associate a stream … | |
Re: I can't understand what for you define both methods in Mobile and Advanced classes and why you can't define virtual PrintAccountType to solve your problem. [code=c++] class Mobile { public: void PrintInfo() { cout << "Mobile::PrintInfo; "; PrintType(); } private: virtual void PrintType() { cout << "Mobile::PrintType\n"; } }; class … | |
Re: [QUOTE=rahul8590;838814]Well i just want to find out , that is there any way where we can find out the various functions and operators / keywords present in a particular header file ....?[/QUOTE] [url]http://www.tenouk.com/[/url] ? | |
Re: Alas, Visual C does not support // comments in C sources. Change them to old (classic) C comments /* */ Apropos: bool, true and false - C++ keywords in C source?.. | |
Re: Take into account that it's impossible to round decimal fractions accurately with binary floating point data ;) Try to avoid pow function using: it's the most ineffective and inaccurate method in that case. | |
Re: Lines to be read: end - start + 1 Pointers allocated: end - start Did you understand? Use code tag with the language specifier!!! [noparse][code=c] sources [/code][/noparse] Always check program arguments: argc == 4 then start > 0 and start <= end. | |
Re: In actual fact in your function you need two pointers (or references) to these "two members of two different structures". Do that. I agree with MrSpigot: "generic" pointer to different structure types in a structure passsed as an argument is a right way to nowhere... | |
Re: May be it helps: [code=c] #define GEND 1 #define NOID 0 /** Returns group id > 0 or 0 if it's not #gid */ int getGroupId(const char* line) { return line && line[0] == '#' && line[1] == 'g' && line[2] == 'i' && line[3] == 'd' &&isdigit(line[4]) ? atoi(line+4) … | |
Re: There are lots of problems with big integers... Can you explain YOUR problems? | |
Re: I don't understand why you want to put words into a structure. A structure has fixed number of fields (four in your case). Do you want to parse four words phrases only?! Apropos, structure access looks like: [code=cplusplus] txt.word1 = ... txt.word2 = ... ... [/code] Better use arrays or … | |
Re: 1. Next time use code tag with the language specifier: [noparse][code=cplusplus] source(s) [/code][/noparse] 2. An array in C++ is not a class. No such beast as [icode]array.length()[/icode] member function. An array is a fixed size data structure. You can't resize an array. However you can dynamically allocate a memory for … | |
Re: Think: [icode]FloatValue (INFINITE_VALUE)[/icode] is not FloatValue variable definition. It's an ordinal expression operator with null effect (in "void position"), the same as [icode]0.0;[/icode]. Evidently, you wanted [code=c++] FloatValue variable_name(INFINITE_VALUE); [/code] Do that and you will catch an exception ;) Probably in your code the compiler generates default FloatValue object and … | |
Re: This code does not [i]wont work[/i], you can't [b]compile[/b] this code (feel the difference ;)). [code=c] struct node *-next; /* Why minus sign? */ [/code] [code=c] typedef struct node n; [/code] Well, you declare n as an alias of [b]struct node[/b] type. Why? [code=c] void create() { ... } [/code] … | |
Re: [QUOTE=CPPRULZ;835262]It is my understanding that in C++ objects of derived classes invoke the derived class' constructor but before the body is executed the base class' constructor is invoked and takes effect and then the derived class' constructor's body is executed. If this knowledge is correct, then what happens if the … | |
Re: Think about another approach: [code=c] struct IntRange { int minval, maxval; }; struct IntRange MinMax(const int* arr, int n) { struct IntRange range = { 0, 0 }; if (arr && 0 < n) { int i; range.minval = range.maxval = arr[0]; for (i = 1; i < n; ++i) … | |
Re: Don't stop C++ programs with exit() function (except on severy run-time errors). Use [icode]return exit_code_value;[/icode] in the main. | |
Re: It's wonderful but just before talking about this code run-time speed and other characteristics correct obvious errors in it. Now you can't [b]compile[/b] this code: arr1 is not declared in the merge function (if it's a global variable better don't display this "improved" sort function)... When you compile this improved … | |
Re: Yet another tip: Now try to invent a function (with two parameters: the question and the right answer) which can ask user, check the answer then return 1 on success or 0 on failure. Sum all returned values then print the test result... | |
Re: A name in C is a statically (before execution) defined program artifact, syntacticaly it's an identifier. There are dynamically (in run-time) created and destroyed data objects and statically (before execution) defined data objects (literal constants). The program can't modify constants (literals). A variable is a named data object. In other … | |
Re: Bad practice wanted? That's bad practice: 1. C-style 2D array allocation/deallocation functions instead of complete 2D array class with full set of operations. 2. Explicit row parameter in destroy2DMatrix: an erron-prone and inconvenient method. 3. Template function definitions after calls: most of C++ compilers can't process this code. 4. 2D … | |
Re: The order of class object constuction (reduced C++ rules, apply recursively): 1. direct base class(es) constructor(s) 2. this nonstatic data member(s) constructor(s) 3. this constructor Revert the order for destruction. Try this: [code=c++] class Member { public: Member(const char* where = ""):whom(where) { cout << "Member " << where << … | |
Re: 1. Next time use code tag with the language specifier: [noparse][code=c++] source(s) [/code][/noparse] 2. No need to repeate virtual specifier in derived classes. 3. >when the method "void update(int progressStatus)" is called the application terminates with an error. Can't reproduce errors, it works as expected. No problems. 4. You must … | |
Re: I'm not sure that this info is enough to reproduce and analyze your program error(s). It looks like a very unstable, error-prone code (what happens if code4 string is too short? Right, you catch an exception or get undefined program behaviour). Some tips: 1. Didn't you know string subscript operator? … | |
Re: A pointer value will never been "deleted" automatically. The life span of the state pointer variable does not bear a relation to the life span of the referred object. In other words, a pointer is a road sign only: "that's a road to Pompeii". May be, the Pompeii was strewn … | |
Re: [QUOTE=CPPRULZ;834740]My textbook says "Constructors cannot be virtual. (Think about it: constructors are called to create new objects. However, if you don't know what type of object you're trying to create, how do you know which constructor to invoke?)" but I am not sure what it means by this. Is it … | |
Re: Declare [icode]const Node* temp[/icode] in const member functions - that's all. These functions must not modify Node fields but you can modify them via [icode]Node* temp[/icode] pointer. Yet another remark: Did you want to implement [b]Linked List[/b] class? If so why did you implement [b]Node[/b] only class? A list is … | |
Re: 1. You forgot to add std:: prefix for vector in template parameter. 2. Barbaric construct: [icode]hfh<=(int)combi[/icode]. Make cast before loop. This code works with VC++ 2008. Yes, it's a bad code: for example, you can initialize 2D vector in a simple, clear and effective manner: [code=c++] truth_table.resize(n,0); truth_table_col.resize(m,truth_table); truth_table.clear(); [/code] | |
Re: Compare [icode]bool operator<(const Data&) const;[/icode] in the class definition and [icode]operator<(Data& someData)[/icode] in the member function implementation. And correct this awful [icode]Data::bool operator<(Data& someData)[/icode] to [code=c++] bool Data::operator<(const Data& ... [/code] | |
Re: It seems it's your homework... See this forum rules... ;) Some tips: 1. the scanner (lexical analyser) works "before" preprocessor so your 1st statement is wrong... 2. The C preprocessor is a one-pass text processor... | |
Re: 1. The rand function never generates "random" numbers. It generates pseudo random numbers (feel the difference ;)). There is a very interesting (and complex) mathematical theory on pseudo random sequences. See, for example: [url]http://en.wikipedia.org/wiki/Random_number_generator[/url] Apropos: it's not so easy to generate "true" random numbers on such deterministic device as a … | |
Re: My 2 cents: It seems the last time when I have used global variables was ~30 years ago in a huge legacy package written in Fortran 66 ;). No needs in global variables at all. Yet another (the only ;)) the extern keyword usage in C++: [icode]extern "C"[/icode] for C … | |
Re: Can you explain why it's a post about [i]void functions[/i]? [code=c++] void Shape(int r, char c1 = '^', char c2 = '#') { for (int i = 0, n = r+r; i <= r; i++) { for (int j = 0; j <= n; j++) cout << (abs(j-r)>i?c1:c2); cout << … | |
Re: Iterators are not numbers. Iterators are abstract pointers (remember pointer arithmetics in C)! | |
Re: [QUOTE=tux4life;832583][iCODE]time(0);[/iCODE] or [iCODE]time(NULL);[/iCODE] returns the system time in seconds ... The C++ Declaration of the 'time()'-function looks as follows: [iCODE]time_t time ( time_t * timer );[/iCODE] So if you pass a NULL-pointer as argument, it will just return the time ... But between the brackets you can also type the … | |
Re: [QUOTE=shea279;832628]K i know how the theory of how to do it.. i just need recommendations on what individual functions to use. my method 1. Find start physical address on disc of target file. 2. Find end physical address on disc of target file. 3. Normal delete file. 4. Recursively fill … | |
Re: Well, now start to study C++ classes from the beginning ;)... You define (but not implement) absolutely useless class Arithmetic. It has three useless private data members (inaccessible and unused) and three declared but undefined member functions (you have basic +-* operators with this functionality in C++). After that you … | |
Re: [url]http://www.andreamaesani.com/home/node/17[/url] May be it helps?.. | |
Re: [code=c++] class WonderPoint { public: bool isValid() const { return valid; } protected: WonderPoint():valid(false) {} bool valid; }; class OrientedPoint:// Oriented POINT- that's cool! public StrangePoint // Fields Medal!!! { public: OrientedPoint()... ... }; [/code] | |
Re: Read this: [url]http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx[/url] | |
Re: I have never seen before: an assignment operator defined for const objects ;)... | |
Re: In other words, you are trying to bind 2D array argument (line 9) with 1D array parameter declared in the line 13, then use 1D array parameter as 2D array in the function body (other lines). Is it surprising that your compiler is surprised at these poetic licenses? | |
Re: [url]http://www.daniweb.com/forums/thread122401.html[/url] General info: [url]http://en.wikipedia.org/wiki/Stable_marriage_problem[/url] Search Google for tons of URLs about SMP applications... | |
| |
Re: 1. Use code tag (see this forum rules): [noparse][code=c++] source code(s) [/code][/noparse] 2. >it prints out the spaces as some junk chars This code can't print anything because you can't compile it: no such namespace as stdin and no such header as <iostream.h> in C++. 3. You are trying to … | |
Re: You can't use that ancient Borland BGI DOS-mode graphics with other compilers. Alas, welcome to the Wonderland of native Windows graphics!.. Of course, you may use more comfortable Forms graphics with MS VC++ or GUI libraries (wxWidgets, for example) for all modern C++ compilers. In any case you must redesign … | |
Re: It's so simple (no need in DaniWeb;)), ask your compiler: [code=c++] typedef std::vector<double> DblVector; typedef std::vector<int> IntVector; DblVector dv; IntVector iv; cout << sizeof(DblVector::size_type) << '\n'; cout << dv.max_size() << '\n'; cout << iv.max_size() << endl; [/code] | |
Re: Some additions: 1. At any case don't name your .h file as io.h: there is (non-standard) system header io.h (low-level file handling) in most of C implementations. It's not an error (system header is <io.h> ), but... 2. No need in extern keyword in function prototypes. | |
Re: The strtoul wants three arguments ;) [code=c++] /// Returns true if it was a good number bool cvtHex(int& n,const char* p) { if (!p) return 0.0; return sscanf(p,"%x",&n) == 1; } /// For PHP expert$ only inline int hexdec(const char* p) { return p?strtoul(p,0,16):0; } [/code] | |
Re: Many years ago in a galaxy far, far away the Turbo C project was a simple text file with .prj extension, for example: [code] mymain.c(mydefs.h,herdefs.h) myfriend.c(herdefs.h) thelib.lib [/code] In other words, it was a list of source modules (with .h files dependencies), libraries, object modules etc... Better follow farhan.foxtrot's advice … |
The End.