1,296 Posted Topics

Member Avatar for fromthatside

Some addition. The original MS windows.h header is a root of the lots of include files: windef.h, winbase.h, wingdi.h and others. In itself it contains few declarations. Open these files (any) and search the __cplusplus identifier. It's the key point to understand why the single window.h used in C and …

Member Avatar for ArkM
0
172
Member Avatar for mabuse

Because of this thread is not closed yet, allow me to add some remarks. On my AMD 5000+ (~2.6 MHz) with VC++ 2008 (release, optimize for speed) this function runs ~3.8 milliseconds (data sizes are 36656 and 25). It's interesting that a variant of this function with std::valarray<double> data runs …

Member Avatar for mabuse
0
475
Member Avatar for salman1354

Please, let's stop an impetuous publicity of std::vector class as universal panacea. It is std::valarray is the most effective STL class for dynamic size arrays of numbers. See, for example: [url]http://stdcxx.apache.org/doc/stdlibref/valarray.html[/url] C++ Standard: [quote]The class template valarray<T > is a one-dimensional smart array, with elements numbered sequentially from zero. It …

Member Avatar for grumpier
0
267
Member Avatar for SurviBee
Member Avatar for ArkM
0
224
Member Avatar for Gentile

Some remarks (it's not the answer): Where's this dilemma in that case? Let's remember: all STL containers are not a family of related classes. Yes, they implement (almost) common set of operations - that's all. No such animal as an abstract container class Adam_container with iterators, push_back or/and insert, erase …

Member Avatar for Gentile
0
222
Member Avatar for marcosjp

How about transmission delay? See, for example: [url]http://en.wikipedia.org/wiki/Network_Time_Protocol[/url] ;)

Member Avatar for ArkM
0
243
Member Avatar for leelingling630

You have a rather strange code to generate exponential distribution. Use RAND_MAX macros from <stdlib.h> (it's not equal to the funny pow expression). [code=cplusplus] const double max_rand = RAND_MAX; ... ... log (x/max_rand) ... [/code] With 32-bit compilers you have huge intervals because of (usually) RAND_MAX is equal 32767 only …

Member Avatar for ArkM
0
197
Member Avatar for bleh1318

If it's the same code, you have obviously uninitialized nm pointer to pointer: [code=cplusplus] noaMux **nm; if (searchNoaMuxes(misrChainVector, scopeString, nm)) { for (int i = (*nm)->getLength()-1; i >= 0; i--) ... [/code] findNoaMux uses it then crashed...

Member Avatar for ArkM
0
139
Member Avatar for BattlingMaxo

Try freeware Ultimate++ based on the same as Dev-C++ MinGW compiler [url]http://www.ultimatepp.org/[/url] before buy VS 2008 Pro (may be not so bad investment ;)). Apropos, Ultimate++ IDE (called TheIDE - what's a wonderful name for yet another IDE) can use VC++ Express too. It has GUI design tools, it's well …

Member Avatar for msk88
0
154
Member Avatar for vadan

Some addition: Regrettably, if class A has no default constructor, you can't declare [icode]B::A obj[10];[/icode] at all. For example: [code=cplusplus] // Modified Ancient Dragon's class class A { private: int aa; public: // No default constructor A(int a):aa(a) {} set(int x) {aa = x;} }; class B { private: A …

Member Avatar for Ancient Dragon
0
115
Member Avatar for gispe

Truth to tell, it's a very strange code. About 11 employees: of course, the loop [icode]for (i = 0; vendedor.legajo!=0, i <= 10; i++)[/icode] repeats 11 times. Take a piece of paper and a pencil... Right: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;)... If you …

Member Avatar for Salem
0
171
Member Avatar for vadan

You need a single private (not public) lock in your connections manager to implement critical sections in getConnection() and freeConnection() member functions. Pseudocode for non-locking solution (when we return no_available_conn value to requestor): [code] Result ConnnectionManager::getConnection() { begin critical section (lock semaphore/mutex) result = no_available_conn search connections array for free …

Member Avatar for ArkM
0
296
Member Avatar for vadan

Probably with such diffuse lock/unlock logic you will have deadlock troubles sooner or later...

Member Avatar for Ancient Dragon
0
116
Member Avatar for timb89

Do you want to keep a poor user typing this grid char by char, line by line under your program control? It is hardly worth it. Let him/her prepare the grid in his/her favorite text editor then load the result text file in your 2D array. If you don't want …

Member Avatar for Sky Diploma
0
102
Member Avatar for ehsan_op

1. You can't COMPILE this snippet: no such API function as creatThread. 2. Your thread do nothing. It starts then dye in silence. What TBS.TbbStart() doing? What's a true problem? Obviously, insufficient info...

Member Avatar for ehsan_op
0
146
Member Avatar for alpine89

In spite of a slightly strange logic this function can't loop forever if you have 5 or more well initialized book records in the book array. It's strange that your search function returns 0 in all cases. It's strange that your search function iterate over external array without its real …

Member Avatar for ArkM
0
200
Member Avatar for floros

fstream.h in Visual Studio 2005? Impossible! Your program gets old stream library includes (with .h names) in old Visual Studio include directory. Check up your installation environment. May be, you try to compile old (legacy) project.

Member Avatar for VernonDozier
0
190
Member Avatar for J-son

1. Always check up scanf return code. It returns a number of successfully converted fields. [code=c] if (scanf("%d",&num) != 1) { /* User type not-a-number or close stdio */ } [/code] 2. Always print some kind of a prompt message, for example: [code=c] printf("Enter an integer: "); if (scanf("%d",&num) != …

Member Avatar for ArkM
0
88
Member Avatar for Alex Edwards

Some additions: In most of C++ implementations reinterpret_cast do nothing (like formally incorrect union trick, see Radical Edward's note). If you want to make a trick, do it honestly (it is open to question, of course ;)). It follows from this that reinterpret_cast is "better" than union trick (in the …

Member Avatar for vijayan121
0
2K
Member Avatar for sonicmas

Regrettably, sonicmas can't follow williamhemsworth's advice without serious troubles: it's a big mistake to save Pessoa class objects as binaries with proposed SaveStruct template!

Member Avatar for sonicmas
0
166
Member Avatar for edouard89

To judge from appearances: 1. The class destructor is not virtual (see requirements) 2. The class constructors do not pass parameters to the parent class (why?). It's interesting to look at the parent class declaration too... 3. No need in public initialize() member function, make it private (or protected). You …

Member Avatar for edouard89
0
124
Member Avatar for OmniX

Be careful: it was not an example of passing by reference! It's passing a pointer by value. The C and early C++ have no passing by reference at all. In modern C++ you may pass parameter by reference: [code=cplusplus] void byRef(int& x) { ... x = 5; } ... int …

Member Avatar for Alex Edwards
0
151
Member Avatar for errorman

Have you ever seen any C++ syntax description? There are tons of syntax and semantics errors and wrong names in your source. 1. endl is ENDL, not END-one. 2. Add semicolon after names declaration. 3. Delete semicolon after main header (write [icode]int main()[/icode] without old-fashioned (void) ). 4. Insert << …

Member Avatar for ArkM
0
89
Member Avatar for sciwizeh

Probably, the worst base for a matrix class is std::vector. You lose all vector advantages (dynamic insert/delete ops) - no need in that features for matrix but gain inevitable std::vector slow access. All matrix operations are time-consuming, so the fastest access to rows, columns and selected elements is a key …

Member Avatar for sciwizeh
0
184
Member Avatar for ambarisha.kn

You need char* pointer, of course. If you want to get packed data, use memcpy() to move your data in the buffer. But you can't use these packed data directly (wrong alignment for double, for example). [code=c] char* pData = malloc(1000000); size_t size; ... short is[2]; double dub; ... size …

Member Avatar for ArkM
0
855
Member Avatar for xyzt

Member functions add nothing to the size of a class object. However if a class has virtual functions, its objects contain some additional (with fixed size) info (so called vtbl pointer) and so sizeof(class_with_virtuals) > sizeof(same_class_without_virtuals). It's interesting to remind: sizeof(class_or_object) must be greater than 0. Look at: [code=cplusplus] class …

Member Avatar for Narue
0
825
Member Avatar for Maxine
Member Avatar for ArkM
0
101
Member Avatar for OmniX

For vectors and valarrays iterators do not provide any advantages (except more cumbersome codes - if you get pay for every LOC, of course). So this supposedly C-style [icode]operator [][/icode] is much more natural vector accessor...

Member Avatar for iamthwee
0
120
Member Avatar for amrhesham9

Yes, I don't have any ideas why to discuss a delivering of a program that demonstraits classes and inheritance on C language forum...

Member Avatar for Ancient Dragon
0
3K
Member Avatar for tspj20

Yet another solution: [code=cplusplus] /** This wrapper class is a slightly adapted solution from: * http://www.cut-the-knot.org/do_you_know/AllPerm.shtml */ template <class T> class Visiter { public: Visiter(const T& v):vref(v),Value(v.size(),-1),level(-1) { visit(0); } virtual ~Visiter() {} private: const T& vref; int level; std::vector<int> Value; void visit(int k) { Value[k] = level; level = …

Member Avatar for ArkM
0
124
Member Avatar for peyman_k

See [url]http://www.inet.hr/~zcindori/mp3class/[/url] It's not a recommendation...

Member Avatar for zcindori
0
242
Member Avatar for zahidullah

It's a WRONG attempt to eat the rest of input line on cin (for example, you get the 1st word and you want to skip other stuff). if cin is attached to a file (not to console), you may get cin.eof condition before '\n' so you never get '\n' in …

Member Avatar for ArkM
0
116
Member Avatar for OmniX

Use std::ostringstream class (from <sstream> header) and its member function str(). It's so simple ;)..

Member Avatar for OmniX
0
169
Member Avatar for Kadence

More precisely: va_args does not work correctly if an argument class objects has non-trivial assignment operator (std::string, for example). You may pass pointers to any class objects safety. However, look at the trick: [code=cpp] void battleShipIowa(const char* what,...) { va_list p; va_start(p,hdr); std::string who; who = *(std::string*)p; // very dangerous, …

Member Avatar for Kadence
0
282
Member Avatar for abhigame

I hope you know that it's impossible in general case. For example, an user might type 1st countings of his Geiger sensor;). It's a series too...

Member Avatar for papuccino1
0
124
Member Avatar for basukinjal

From [url]http://thesaurus.maths.org/mmkb/entry.html?action=entryById&id=3340:[/url] [quote]The mapping which takes every element to itself; it leaves every element unchanged. It is sometimes written I, so that I(x)=x for all x in a particular domain.[/quote] May be you want to get reverse mapping or what else?..

Member Avatar for ArkM
0
123
Member Avatar for abhigame

Look at [url]http://www.answers.com/topic/library-sort[/url] Download an original article (PDF) via link on this page. See also a brief description in wikipedia: [url]http://en.wikipedia.org/wiki/Library_sort[/url] I'm too lazy to search ready-to-use C++ implementations now ;)..

Member Avatar for ArkM
0
111
Member Avatar for bomtk

It's a rather strange snipped: a matrix is a 2D rectangualar array but the code uses three indicies and has a lot of magic numbers (+8, +3 etc)... If you want to collect a real 2D matrix 1000x1000 (of doubles, for example), look at this code sceleton: [code=cpp] double** bigmat; …

Member Avatar for ArkM
0
121
Member Avatar for NoGood123

Tremendous Saga of Bubble Sorting! Thank you, all members of this Instant/FastFood C++ society!

Member Avatar for ArkM
0
330
Member Avatar for RayvenHawk

It was a very interesting remark especially taking into account: 1. No classes in pure C 2. It's C++ forum. ;)

Member Avatar for Undertech
0
136
Member Avatar for daviddoria

Never use std::vector for numbers crunching (in scientific or engineering calculations). This STL container never intended for fast calculations. If you don't want to take much trouble over new/delete, use std::valarray class. For example, times to calculate sum of 10000000 double type elements: [code] 1. vector[]: ~50 milliseconds 2. vector/iterator: …

Member Avatar for ArkM
0
150
Member Avatar for bincy ashok

Why stack? Why "pointer implementation of the data structure"? All you need: fgetc(f) to read a file char by char plus a level counter plus a simple logic: [code] search '/'... if the next char is '*' then comment started, search '*' ... and scan again... [/code] ... and so …

Member Avatar for WaltP
0
99
Member Avatar for Risame

As far as I know no namespaces and string class (no STL at all) in BC++ 3.1. Old streams implementation via <iostream.h> - that's all...

Member Avatar for Radical Edward
0
253
Member Avatar for boradbhavesh
Member Avatar for Salem
0
88
Member Avatar for T&T

OK, start from this link: [url]http://www.daniweb.com/forums/announcement118-2.html[/url]

Member Avatar for ithelp
0
68
Member Avatar for CoolGamer48

Think about 64-bit portability (why not?): [icode]hex << 8) >> 24[/icode] does not work if sizeof(unsigned int) > 4. Make user input argument safety in 100% portable manner, for example: [code=cplusplus] rzb::color::color(unsigned int hex) { m_alpha = (hex & 0xFF); m_blue = ((hex>>=8) & 0xFF); m_green = ((hex>>=8) & 0xFF); …

Member Avatar for ArkM
0
243
Member Avatar for scream2ice

Some remarks: The C library is a standard part of the C++ library. In particular, the atoi() function is declared in <cstdlib> C++ library header.

Member Avatar for invisal
0
331
Member Avatar for coveredinflies

Don't worry, simply form a habit to read (then invent) recursive algorithmes (apropos, never calculate factorial in this manner;)). How about: [code=cplusplus] int factorial(int n) { return n <= 1? 1: n*factorial(n-1); } [/code] Simple and clear code (with guarantee of as usually undetected integer overflow;))...

Member Avatar for coveredinflies
0
157
Member Avatar for dmanw100

Or simply use old good atoi() from <cstdlib>: [code=cplusplus] char* value_a = "123456"; int final = std::atoi(value_a); [/code]

Member Avatar for ArkM
0
181
Member Avatar for Traicey

C is a language and SQL is a language. Can you connect anything to a language? All well known SQL servers have a client application programming interface (API) in C.

Member Avatar for death_oclock
0
107

The End.