1,247 Posted Topics
Re: (most) windows programs are written to run against an environment subsystem. the subsystem is specified in the PE header of the executable image and is placed there by the linker. currently, your program is being linked with the linker switch [B]/SUBSYSTEM:WINDOWS[/B]. this implies that your program does not require a … | |
Re: > where each column vector is normally distributed, between -1 and +1, and the row vectors are uniformly distributed between -1 and +1 this is mathematically impossible. if row vectors are uniformly distributed between -1 and +1, any element in any row (read any element in your 2d array) is … | |
Re: [ICODE]void foo(int* a)[/ICODE] and [ICODE]void foo(int a[])[/ICODE] are identical; they are not distinguishable from each other. they are the same [ICODE]void foo(int(&a) [N])[/ICODE] [B]a[/B] is a reference to an array of exactly [B]N[/B] elements. disadvantage: [B]N[/B] must be a constant known at compile time. advantage: size of the array is … | |
Re: [quote=jbennet;386884]Also bear in mind that some old versions of turbo c++ and nearly all versions of Visual Studio do not adhere to the standard[/quote]the c++ front-end from Edison Design Group is the [B]only[/B] implementation to support the complete C++ standard ISO/IEC 14882:2003. see: [url]http://www.edg.com/index.php?location=c_lang[/url] a good test for compiler conformance … | |
a string which can be used ala std::string, preserves case, but comparisons are not case sensitive. | |
choose a random element from a sequence when a. you do not know how many elements are there before hand b. you want to make one single pass through the sequence c. you do not want to use auxiliary storage | |
Re: see: [url]http://www.daniweb.com/forums/showthread.php?p=538484[/url] | |
Re: you could write a custom allocator that tracks calls to allocate and deallocate. [code=c++]#include <map> template< typename T > struct myallocator : public std::allocator<T> { typedef std::allocator<T> base ; typedef typename base::size_type size_type; typedef typename base::difference_type difference_type; typedef typename base::pointer pointer; typedef typename base::const_pointer const_pointer; typedef typename base::reference reference; typedef … | |
Re: you could use [ICODE]boost::progress_display[/ICODE] [url]http://www.boost.org/libs/timer/timer.htm[/url] [code=c++]#include <boost/progress.hpp> #include <iostream> #include <unistd.h> int main() { enum { LINES_IN_FILE = 1000 } ; boost::progress_display display( LINES_IN_FILE, std::cout ) ; for( int i=0 ; i<LINES_IN_FILE ; ++i ) { // process one line, add to database usleep( 10 ) ; // simulate taking … | |
Re: > ...maybe the array is automatically cleared from memory when the application closes... right, provided your program is running under an os ( like unix, windows, linux ... ) which gives a separate virtual address space for each process. when a process terminates, all the resources it owns are reclaimed … | |
Re: normally, you would not try to write a web server yourself. instead you would host your web application inside an application server like apache or IIS. and let that take care of not merely threading, but also a lot of other issues which need to be addressed (security, cookie management, … | |
Re: [quote=bling_bling_vr6;345628]... but I'm stuck on how to avoid filling it with duplicate values. I'm assuming that i'll have to use either a linear or binary search function while filling the array...[/quote] 1. you cannot do a binary search; the array is not ordered. 2. a linear search is possible, but … | |
Re: you can answer this yourself if you write a small test program and run it. for example: [code=c++]#include <iostream> struct A { A() { std::cout << "A::default constructor\n" ; } A( const A& ) { std::cout << "A::copy constructor\n" ; } A& operator= ( const A& ) { std::cout << … | |
Re: > can u pass template class objects as parameters to friend functions of the same class?? obviously, you can. but you need to let the compiler know that they are templates. [code=c++]#include <iostream> // declare things first template< typename T > class array ; template< typename T > std::istream& operator>> … | |
Re: you need to enable RTTI. (use compiler switches for this.) either you have turned it off by using the switch /GR- or you are using a fairly old version of the microsoft compiler. turn it on with the compiler switch /GR [url]http://msdn.microsoft.com/en-us/library/we6hfdy0.aspx[/url] | |
Re: [B]> man mmap[/B] <Enter> at the command prompt on your system. it should give you all the information that you require.you would see something like this: [url]http://www.freebsd.org/cgi/man.cgi?query=mmap&apropos=0&sektion=0&manpath=FreeBSD+7.0-stable&format=html[/url] | |
Re: read the following pages and you should be ok: [url]http://www.relisoft.com/science/CrcMath.html[/url] [url]http://www.relisoft.com/science/CrcNaive.html[/url] [url]http://en.wikipedia.org/wiki/Cyclic_redundancy_check#Computation_of_CRC[/url] [url]http://www.relisoft.com/science/CrcOptim.html[/url] | |
Re: > declare it as private and just leave an empty implementation? ideally, declare it as private and do not define it. > Is this common/useful? useful, yes. common, not all that much. if there is a class that you write (for example a window), and want its instances not to … | |
Re: > It keeps saying: > Failed to connect with the server : Bad file descriptor that says all that needs to be said, doesn't it? [code]int websock; [COLOR="Red"]// websock is an uninitialized int[/COLOR] webaddress.sin_family = AF_INET; webaddress.sin_addr.s_addr = inet_addr("http://www.google.com/index.html"); webaddress.sin_port = htons(80); if(connect(websock, ... [COLOR="Red"]// websock is not a file … | |
Re: [CODE=C++]struct base { virtual std::ostream& write( std::ostream& stm ) const = 0 ; // ... }; inline std::ostream& operator<< ( std::ostream& stm, const base& object ) { return object.write( stm ) ; // polymorphic } // ---------------------------------------------------------------------------------------------------- struct derived : base { // override virtual std::ostream& write( std::ostream& stm ) … | |
Re: [QUOTE][code=cplusplus] template <typename C> typename C::iterator SlowFind(C& c, const typename C::value_type& v) { typename C::iterator i; for (i = c.begin(); i != c.end() && *i != v; ++i) ; return i; } [/code][/QUOTE] this is broken when C is a const container. c.begin() and c.end() returns objects of type C::const_iterator. … | |
Re: have a look at the standard header <utility>. it defines std::pair and std::make_pair. [CODE=c++98]template <typename First, typename Second> struct Pair { First f; Second s; Pair( const First& ff, const Second& ss ) : f(ff), s(ss) {} // etc }; template <typename First, typename Second> inline Pair<First,Second> makePair( const First& … | |
Re: bulk rename of all the .wav files in one go and updating the text in all the .phr files at another time can leave you in a messy state in the event of a crash (you would have to restart all over again after restoring from backups). you could consider … | |
Re: in adition, change [ICODE]int size = 100;[/ICODE] to [ICODE][COLOR="Red"]const[/COLOR] int size = 100;[/ICODE] size of an array must be a constant known at compile time. | |
Re: this is nothing specific to constructors or passing parameters to functions. it is just the application of the C++ rules for resolving a call to an overloaded function. [code=c++]#include <iostream> void foobar( int& arg ) { std::cout << "foobar( int& )\n" ; } void foobar( const int& arg ) { … | |
Re: the general knapsack problem and the subset sum problem are NP-hard, but not NP-incomplete. so there are no polynomial-time algorithms. but it is one of the easy NP-complete problems to solve. it can be solved (in pseudo-polynomial time) using dynamic programming. AFAIK, using a Branch and bound algorithm [url]http://en.wikipedia.org/wiki/Branch_and_bound[/url] should … | |
Re: > What I look for now is a fast way to convert from double to char* > I have a problem to find this conversion. a. compile C++ source to generate native code, not IL that is interpreted at run-time. b. enable optimizations. with these two, this is what i … | |
Re: > #pragma - what does it mean to understand what #pragma is see: [url]http://msdn.microsoft.com/en-us/library/d9x1s805(vs.71).aspx[/url] for the specific #pragma directives that are in your code, refer to your compiler docs. > what does word __fastcall mean __fastcall is an implementation-defined keyword in microsoft and several other compilers. it specifies a particular … | |
Re: have each of the two stacks to store a [B]reference[/B] to a std::deque. initialize them to refer to the [B]same[/B] std::deque. write a wrapper class to hold the two stacks. [code=C++]template< typename T > struct dual_stack { struct first_stack { explicit first_stack( std::deque<T>& seq ) : sequence(seq) {} // implement … | |
Re: consider using the std::tr1 polymorphic function wrappers. this would allow using free functions, member functions and function objects in a polymorphic way. if your compiler does not ship with tr1, you can use boost::function in the interim. [url]http://www.boost.org/doc/libs/1_36_0/doc/html/function/tutorial.html#id2903300[/url] [code=c++]#include <iostream> #include <string> #include <map> #include <vector> // tr1: #include <functional> … | |
Re: > But I still find it ackward, that there are no possibility to do it. > I can handle special cases when, I have different INPARS as long as the method is void. > But it's not possible to do it when you have a return type. you can get … | |
Re: a [ICODE]std::tr1::shared_ptr[/ICODE] cannot correctly hold a pointer to a dynamically allocated array. AFAIK, there is no such smart pointer in tr1. you could use boost::shared_array (tr2) instead. [url]http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/shared_array.htm[/url] [ICODE]std::tr1::shared_ptr[/ICODE] to a [ICODE]std::vector[/ICODE] is a far more flexible alternative. | |
Re: for the predefined streams, it's safe to mix C stdio and C++ iostreams. you can safely use [ICODE]stdin[/ICODE] and [ICODE]std::cin[/ICODE] in the same program; the C++ Standard guarantees that it will work the way you would expect it to. if you don't need to mix C stdio and C++ iostreams … | |
Re: >> The above is common practice, but it is easily broken. >> Imagine, for example, a class that supports its own operator&() ... >> The most useful way I've found to do an assignment operator is; >> ... >> the only cost is associated with creating a temporary copy of … | |
Re: perhaps the easiest way is to use the iostream formatted output facilities: [code=c++]#include <iostream> #include <string> #include <sstream> #include <iomanip> int main() { double a = 2.5632, b = 2.5652 ; std::ostringstream strout ; strout << std::fixed << std::showpoint << std::setprecision(2) << "a: " << a << " b: " … | |
![]() | Re: a little less verbose, and a little more efficient: [CODE=C++]#include <vector> #include <string> int main ( int argc, char** argv ) { std::vector< std::string > arguments( argv, argv+argc ) ; } [/CODE] |
Re: > i would like to avoid doing 4 times 2 shift for each char. > For each char i do 4 shift operations and 4 bitwise AND's, thats 8 bitwise operations. you can reduce it to just 4 AND operations by using 4 bit masks. [code=c++]#include <iostream> #include <limits> int … | |
Re: > As a destructor releases memory for an object ... a destructor does not release memory. it deinitializes an object and after it executes, what is left is uninitialized memory (earlier occupied by the object, whose lifetime is now over). how (or if) this memory is released depends on the … | |
![]() | Re: also have a look at codeville [url]http://codeville.org/[/url] it is one one of the easiest to use. ![]() |
Re: > while(fin) is running endlessly .. in general, when reading an entire file, it is a good idea to embed the input statement inside the while loop's condition. this would eliminate a lot of subtle errors. and the loop will exit once eof is reached. eg. [code=c++]#include <fstream> int main() … | |
Re: valarrays were introduced with the idea that it might encourage C++ compiler developers for vector processors to implement them as built-in types (the compiler could emit code to optimize the use of the vector pipeline). See Bjarne Stroustrup, "The C++ Programming Language: Third Edition", Chapter 22 Numerics, Section 4 Vector … | |
Re: if you absolutely need a base class Chart (with virtual functions), a hack would be to overload the AddElement function. i would prefer using templates for your containers as suggested by Narue in the other thread. and as for this issue: > ... generic template<class T> container and have a … | |
Re: any 3-combination of the N-set would consist of numbers at 3 different positions in the array; you could choose positions i,j,k out of these three such that i<j<k holds. so doesn't the problem reduce to generating all unique 3-combinations of an N-set. several algorithms to do this efficiently exist. Chase's … | |
Re: [CODE]Derived d; Base *p = reinterpret_cast< Base*>(&d); [/CODE] > I found that this is also legal-- it will compile. it will work correctly if and only if the anonymous base class sub-object is at an offset of zero in the derived class object. do not get lulled into a false … | |
Re: > Could it be because i am entering the string 'key' with spaces? yes > how would i fix it? use [ICODE]std::getline[/ICODE] [url]http://www.cppreference.com/cppstring/getline.html[/url] | |
Re: > Is there any real different between using an union between two types and a reinterpret_cast between two types yes, there are quite a lot of differences. a union reinterprets the layout of memory (depending on which member is accessed). a reinterpret_cast is a conversion operator. the conversions that can … | |
![]() | Re: [url]http://geany.uvena.de/manual/0.14/index.html#tags[/url] ![]() |
Re: see IS 9.4.2/4 [QUOTE]"...The member shall still be defined in a namespace scope if it is used in the program and the namespace scope definition shall not contain an initializer".[/QUOTE] GCC is conforming. static constant member object is 'used' (in main) and, therefore, has to be defined. the main issue … | |
Re: Stan Lippman's Inside the C++ Object Model [url]http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545[/url] | |
Re: [ICODE]> cat my_file.txt | grep ^ | wc -l[/ICODE] |
The End.