1,296 Posted Topics
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: To l4z3r: It's not the same as Ancient Dragon's (RIGHT) solution! | |
Re: 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 … | |
Re: How about transmission delay? See, for example: [url]http://en.wikipedia.org/wiki/Network_Time_Protocol[/url] ;) | |
Re: 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 … | |
Re: 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... | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: Probably with such diffuse lock/unlock logic you will have deadlock troubles sooner or later... | |
Re: 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 … | |
Re: 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... | |
Re: 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 … | |
Re: 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. | |
Re: 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) != … | |
Re: 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 … | |
Re: 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! | |
Re: 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 … | |
Re: 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 … | |
Re: 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 << … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: It seems WLC is a proprietary file format. Buy WISCO Computing Word Power and enjoy... | |
Re: 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... ![]() | |
Re: Yes, I don't have any ideas why to discuss a delivering of a program that demonstraits classes and inheritance on C language forum... | |
Re: 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 = … | |
Re: See [url]http://www.inet.hr/~zcindori/mp3class/[/url] It's not a recommendation... | |
Re: 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 … | |
Re: Use std::ostringstream class (from <sstream> header) and its member function str(). It's so simple ;).. | |
Re: 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, … | |
Re: 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... | |
Re: 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?.. | |
Re: 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 ;).. | |
Re: 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; … | |
Re: Tremendous Saga of Bubble Sorting! Thank you, all members of this Instant/FastFood C++ society! | |
Re: It was a very interesting remark especially taking into account: 1. No classes in pure C 2. It's C++ forum. ;) | |
Re: 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: … | |
Re: 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 … | |
Re: 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... | |
Re: Look at [url]http://www.bearcave.com/random_hacks/permute.html[/url] | |
Re: OK, start from this link: [url]http://www.daniweb.com/forums/announcement118-2.html[/url] | |
Re: 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); … | |
Re: 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. | |
Re: 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;))... | |
Re: Or simply use old good atoi() from <cstdlib>: [code=cplusplus] char* value_a = "123456"; int final = std::atoi(value_a); [/code] | |
Re: 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. |
The End.