1,296 Posted Topics

Member Avatar for power_computer

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 …

Member Avatar for power_computer
0
116
Member Avatar for dekaya

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 …

Member Avatar for dekaya
0
2K
Member Avatar for edb500

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 …

Member Avatar for ArkM
0
80
Member Avatar for rahul8590

[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] ?

Member Avatar for rahul8590
0
122
Member Avatar for VelcroMan

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

Member Avatar for ArkM
0
185
Member Avatar for songweaver

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.

Member Avatar for songweaver
0
1K
Member Avatar for metal_butterfly

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.

Member Avatar for metal_butterfly
0
93
Member Avatar for beatlea

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

Member Avatar for beatlea
0
118
Member Avatar for metal_butterfly

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

Member Avatar for metal_butterfly
0
108
Member Avatar for mimis

There are lots of problems with big integers... Can you explain YOUR problems?

Member Avatar for tux4life
0
251
Member Avatar for awk

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 …

Member Avatar for awk
0
129
Member Avatar for epan

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 …

Member Avatar for ArkM
0
75
Member Avatar for tron_thomas

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 …

Member Avatar for ArkM
0
158
Member Avatar for sat4ever0606

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

Member Avatar for death_oclock
0
148
Member Avatar for CPPRULZ

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

Member Avatar for ArkM
0
99
Member Avatar for Dewey1040

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

Member Avatar for Dewey1040
0
201
Member Avatar for free radical

Don't stop C++ programs with exit() function (except on severy run-time errors). Use [icode]return exit_code_value;[/icode] in the main.

Member Avatar for free radical
0
191
Member Avatar for c++noobie

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 …

Member Avatar for c++noobie
0
110
Member Avatar for I-R

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

Member Avatar for tux4life
0
123
Member Avatar for wasge

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 …

Member Avatar for wasge
0
229
Member Avatar for tux4life

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 …

Member Avatar for tux4life
0
231
Member Avatar for CPPRULZ

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

Member Avatar for ArkM
0
102
Member Avatar for eduardocoelho

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 …

Member Avatar for ArkM
0
232
Member Avatar for Soccerace

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

Member Avatar for Soccerace
0
70
Member Avatar for OffbeatPatriot

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 …

Member Avatar for MrSpigot
0
99
Member Avatar for CPPRULZ

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

Member Avatar for ArkM
0
142
Member Avatar for TheFueley

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 …

Member Avatar for TheFueley
0
185
Member Avatar for guest7

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]

Member Avatar for guest7
0
102
Member Avatar for Hilariousity

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]

Member Avatar for Hilariousity
0
2K
Member Avatar for csurfer

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

Member Avatar for csurfer
0
144
Member Avatar for Lukezzz

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 …

Member Avatar for DavidB
0
142
Member Avatar for theories

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 …

Member Avatar for ArkM
0
87
Member Avatar for RoselineM

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

Member Avatar for DangerDuke
0
128
Member Avatar for daviddoria

Iterators are not numbers. Iterators are abstract pointers (remember pointer arithmetics in C)!

Member Avatar for StuXYZ
0
95
Member Avatar for sgw

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

Member Avatar for ArkM
0
23K
Member Avatar for shea279

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

Member Avatar for ArkM
0
690
Member Avatar for jimjohnson123

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 …

Member Avatar for ArkM
0
146
Member Avatar for manjuannthomas
Member Avatar for daviddoria

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

Member Avatar for daviddoria
0
122
Member Avatar for usman2k4u
Member Avatar for r0flc0pter
Member Avatar for ArkM
0
155
Member Avatar for emiller7

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?

Member Avatar for emiller7
0
3K
Member Avatar for miniroselit

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

Member Avatar for ArkM
0
98
Member Avatar for massivefermion
Member Avatar for neelima156

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 …

Member Avatar for neelima156
0
130
Member Avatar for senidaljeet

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 …

Member Avatar for ArkM
0
85
Member Avatar for maru2

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]

Member Avatar for StuXYZ
0
216
Member Avatar for gsingh2011

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.

Member Avatar for ArkM
0
91
Member Avatar for Talguy

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]

Member Avatar for ArkM
0
3K
Member Avatar for bharavn

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 …

Member Avatar for ArkM
0
114

The End.