1,247 Posted Topics

Member Avatar for daviddoria

[ICODE]Point B();[/ICODE] is the declaration of a function called 'B' which takes no arguments and returns a Point. modify to [ICODE]Point B ;[/ICODE] and you have the definition of a variable called 'B' which is of type Point (initialized via the default constructor).

Member Avatar for Narf!!!
0
213
Member Avatar for perun_x
Member Avatar for vijayan121
0
110
Member Avatar for JaR

the typical work around (as exemplified by the standard library containers and function objects) is to have the generic type announce dependent types via suitable typedefs. [code=c++]#include <vector> #include <iostream> #include <typeinfo> template <class T> class CObject { public: typedef T numeric_type ; typedef std::vector<T>* output_type ; inline virtual ~CObject …

Member Avatar for JaR
0
2K
Member Avatar for Agni

to reproduce the white spaces in the original in the reversed sentence: [code=c++]#include <string> #include <algorithm> #include <iterator> #include <iostream> #include <ctype.h> template< typename REV_CHAR_ITER > void print_reverse( REV_CHAR_ITER rbeg, REV_CHAR_ITER rend ) { REV_CHAR_ITER found = std::find_if( rbeg, rend, ::isspace ) ; std::copy( found.base(), rbeg.base(), std::ostream_iterator<char>(std::cout) ) ; if( …

Member Avatar for Agni
0
348
Member Avatar for Manutebecker

to just draw 52 cards in random order without duplicate draws, just fill an array/vector of size 52 with values [1,52] and do a [ICODE]std::random_shuffle[/ICODE] on it. to make 52 draws, marking/discarding duplicate draws, we can avoid the 52 linear searches: [code=c++]#include <iostream> #include <cstdlib> #include <ctime> int main() { …

Member Avatar for vijayan121
0
101
Member Avatar for n.aggel

[CODE]struct align1 { double a; char b; int c; short d; };[/CODE] > why the compiler pads the structure in the end? hint: 1. does the struct [ICODE]align1[/ICODE] have an alignment requirement? 2. if we create an array [ICODE]align1 array[5] ;[/ICODE] would the alignment be right for every element in …

Member Avatar for n.aggel
0
173
Member Avatar for aecsant

you could do it this way. [CODE=C++]#include <iostream> struct SubFoo ; struct Foo { Foo SubFoo() const ; }; struct SubFoo : Foo { SubFoo() { std::cout << "SubFoo constructor\n" ; } } ; Foo Foo::SubFoo() const { return ::SubFoo() ; } int main() { Foo foo = Foo().SubFoo(); } …

Member Avatar for Prabakar
0
261
Member Avatar for Alex Edwards

[code=c++] #include <iostream> #include <limits> // addition can be done using bitwise xor // with adjustments for carry bits unsigned int plus( unsigned int first, unsigned int second ) { unsigned int carry = first & second ; // the carry bits unsigned int result = first ^ second ; …

Member Avatar for invisal
0
173
Member Avatar for GFXtm

the error is this: error C2993: 'float' : illegal type for non-type template parameter 'zero' non-type template parameters are restricted to a. constant integral values (including enumerations) b. pointers or references to objects with external linkage. the simplest work around is: take the parameter as an argument to the constructor. …

Member Avatar for vijayan121
0
447
Member Avatar for himsymcpp

> Windows heap is not the same thing as CRT heap and to complicate matters, there may be several win32 heaps (and several CRT heaps) in a process. if an exe or shared object (DLL) is linked with the static C/C++ runtime library, then the module has its own private …

Member Avatar for ArkM
0
2K
Member Avatar for simeon.andreev

[url]http://www.cppreference.com/cppstack/index.html[/url] [code=c++] #include <stack> struct mystruct { /* whatever */ } ; int main() { std::stack<int> int_stack ; std::stack<mystruct> stack_of_mystruct ; int_stack.push(100) ; // etc. }[/code]

Member Avatar for simeon.andreev
0
121
Member Avatar for brain

you can get the effect that you intended (specializing the nested class without also specializing the containing class) this way: delegate the nested template to another template at some namespace scope which has an explicit specialization: [code=c++] #include <iostream> namespace A { namespace impl_detail { // generalization: template < typename …

Member Avatar for vijayan121
0
136
Member Avatar for jack1234

in general prefer catching exceptions by reference rather than by value. if the actual object thrown is of a derived class, catching by reference avoids slicing (virtual functions will behave polymorphicaly, the class can be abstract). it also has the minor performance advantage of avoiding the making of a copy …

Member Avatar for vijayan121
0
235
Member Avatar for Gusts

this makes only one pass through the array (breaking when the duplicate is found). however, the requirement 'You can access each array member only once' is violated. also, it modifies the array as it goes along; perhaps even this is not allowed. [code=c++] int duplicate_number( int* array, std::size_t N ) …

Member Avatar for Alex Edwards
0
307
Member Avatar for littlestone

if the pattern matching is done on a very long sequence of characters (eg. searching for the occurrence of a particular phrase or word in a large book), there are several interesting algorithms. here is a link that explores some of them. [url]http://www.jea.acm.org/ARTICLES/Vol4Nbr2/index.html[/url]

Member Avatar for vijayan121
0
327
Member Avatar for sangham

consider using a textual format (maybe xml). text is a universal format; it is easy for people to read, write, and edit. and the network payload is easier to inspect, to modify and to debug. text data is transparent and help enforce encapsulation between programs. a textual protocol tends to …

Member Avatar for mitrmkar
0
97
Member Avatar for n.aggel

[QUOTE][COLOR="Red"]n[/COLOR] is made automatically from [COLOR="Red"]n.o[/COLOR] by running the linker (usually called ld) via the C compiler. The precise command used is ... This rule does the right thing for a simple program with only one source file. It will also do the right thing if there are multiple object …

Member Avatar for n.aggel
0
164
Member Avatar for brk235

> i need ti update x,y and z values for all the objects simultaneously...not one by one... if you need to share members for some (not all) objects (perhaps for some period of time), consider using [ICODE]std::tr1::shared_ptr[/ICODE] or [ICODE]boost::shared_ptr[/ICODE] to hold the members. [url]http://www.boost.org/doc/libs/1_35_0/libs/smart_ptr/shared_ptr.htm[/url] shared pointers will also allow sharing …

Member Avatar for vijayan121
0
124
Member Avatar for zhouj

a cv-qualifier suffix following the (non-static) member function's parameter list is a specifier for the [ICODE]this[/ICODE] pointer which is an implicit parameter to the function. overloading on cv-qualifiers is overloading on the type of the [ICODE]this[/ICODE] pointer; and normal overloading resolution applies. eg. [code=c++]#include <iostream> #include <typeinfo> struct some_class { …

Member Avatar for vijayan121
0
171
Member Avatar for abhimanyuancha

IPv4: [ICODE]man gethostbyname[/ICODE] [url]http://www.freebsd.org/cgi/man.cgi?query=gethostbyname&sektion=3&apropos=0&manpath=FreeBSD+7.0-stable[/url] IPv6 and other address families: [ICODE]gethostbyname2[/ICODE] [ICODE]getaddrinfo[/ICODE] [url]http://www.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3&apropos=0&manpath=FreeBSD+7.0-stable[/url] [code=c++]// IPv4 address lookup #include <netdb.h> #include <arpa/inet.h> #include <iostream> int main() { const char* const host = "www.toolbar.google.com" ; const hostent* host_info = 0 ; for( int attempt=0 ; (host_info==0) && (attempt<3) ; ++attempt ) host_info = …

Member Avatar for vijayan121
0
660
Member Avatar for zzmgd6

blog entry on how to do this (Matt Pietrek) [url]http://blogs.msdn.com/matt_pietrek/archive/2004/08/25/220330.aspx[/url]

Member Avatar for vijayan121
0
2K
Member Avatar for Agni

[url]http://www.pdc.kth.se/training/Tutor/Basics/dbx/index-frame.html[/url] [url]http://www.glue.umd.edu/afs/glue.umd.edu/system/info/olh/Programming/C_Programming_Tools_on_Glue/A_dbx_Tutorial/[/url]

Member Avatar for Agni
0
124
Member Avatar for brain

predicate versions of [ICODE]std::mismatch[/ICODE] [ICODE]std::search[/ICODE] [ICODE]std::lexicographical_compare[/ICODE] [ICODE]std::equal[/ICODE] etc.

Member Avatar for brain
0
102
Member Avatar for brain

[B]concept[/B]: the value_type of a standard container (the type of the object stored in the container) is required to be [I][B]Assignable[/B][/I] [url]http://www.sgi.com/tech/stl/Assignable.html[/url] a [ICODE]const T[/ICODE] ( or for that matter a [ICODE]T&[/ICODE] ) is not [I][B]Assignable[/B][/I] and cannot be the value_type in a standard container.

Member Avatar for brain
0
295
Member Avatar for titaniumdecoy

> typename is not followed by a name, which I find confusing since the intent is to declare a template template type (ttp), the identifier following typename is just a place-holder (like the name of a formal parameter to a function) and can be omitted. [url]http://www.comeaucomputing.com/techtalk/templates/#ttp[/url] a standard container has …

Member Avatar for vijayan121
0
115
Member Avatar for yifli

you are trying to multiply a [ICODE]Matrix<double>[/ICODE] and a [ICODE]Point<float>[/ICODE] the overloaded binary * operator needs to be: [CODE]template<class T> class Matrix { // ... [COLOR="Red"]template< typename U > [/COLOR] Point<[COLOR="Red"]U[/COLOR]> operator* (const Point<[COLOR="Red"]U[/COLOR]>& p) const { return Point<[COLOR="Red"]U[/COLOR]>(0,0,0); } };[/CODE] also, [CODE] template<class T, class C> void foo(T x, …

Member Avatar for vijayan121
0
124
Member Avatar for titaniumdecoy

to enforce const-correctness (a good idea), use [ICODE]const[/ICODE] as required. eg. [code=c++] #include <cstddef> struct Piece ; struct board { enum { N = 8 } ; struct the_row { const Piece* operator[] ( std::size_t j ) const { return j<board::N && row!=0 ? row[j] : 0 ; } private …

Member Avatar for titaniumdecoy
1
123
Member Avatar for Vallnerik25

> So I could write something like this: ... no, you can't. you need to write something like: [code]std::size_t max = 0; // Number set by user at execution // ... long (*pBigArray)[100][100] = new long [max][100][100];[/code] > Can someone tell me why I can't write the above? for performing …

Member Avatar for Vallnerik25
0
108
Member Avatar for integer*09

the simplest (and the most efficient) way to copy a text file (C++): [code] std::ifstream srce( inputfilename ) ; std::ofstream dest( outputfilename ) ; dest << srce.rdbuf() ; [/code] if the escape sequence encodings are the same for both files (for instance they are on the same file system), you …

Member Avatar for integer*09
0
175
Member Avatar for Noxes

the exercises (many of them open-ended) given in C++ Primer, 3/E [url]http://www.pearsonhighered.com/academic/product/0,,0201824701,00%2Ben-USS_01DBC.html[/url] perhaps, along with the C++ Primer Answer Book [url]http://search.barnesandnoble.com/C-Primer-Answer-Book/Clovis-L-L-Tondo/e/9780201309935[/url]

Member Avatar for Alex Edwards
0
98
Member Avatar for TheBeast32

> an algorithm better than FFT for getting large numbers(of the order of 10 power 30 or more)? FFT multiplications are efficient when numbers are very large. the other popular multiplication algorithms are Karatsuba and Toom-3. [url]http://gmplib.org/manual/Multiplication-Algorithms.html#Multiplication-Algorithms[/url] in general Karatsuba is suitable for smaller numbers, Toom-3 for larger numbers and …

Member Avatar for TheBeast32
0
110
Member Avatar for dougy83

asynchronous write to a file by [ICODE]aio_write[/ICODE] [url]http://www.freebsd.org/cgi/man.cgi?query=aio_write&apropos=0&sektion=2&manpath=FreeBSD+7.0-stable&format=html[/url] is POSIX.1, and should work on linux.

Member Avatar for dougy83
0
1K
Member Avatar for ninjaneer

> method that I can use to force M$ windows to listen to my priority designations? run under an account with elevated privileges. on a normal system, only the memory manager worker threads (balance set manager, modified page writer and mapped page writer) run under real-time priority. by default, only …

Member Avatar for ninjaneer
0
112
Member Avatar for SteveDB

[code]case 1 : [COLOR="Red"]float hipvalley();[/COLOR] // this is the Hip/Valley choice.[/code] that is merely a declaration of the function hipvalley. to invoke the function (and ignore its result), write [code]case '1' : [COLOR="Red"]hipvalley();[/COLOR] // this is the Hip/Valley choice.[/code]

Member Avatar for SteveDB
0
121
Member Avatar for Superfat

[code=c++] #include <cstdlib> #include <string> inline char random_digit() { return '0' + std::rand() % 10 ; } inline std::string random_pin( std::size_t ndigits ) { std::string pin ; for( std::size_t i = 0 ; i < ndigits ; ++i ) pin += random_digit() ; return pin ; } [/code]

Member Avatar for tesuji
0
171
Member Avatar for Ellisande

or [code]// ... int Strength = 5 ; int Intelligence = 2 ; int Agility = 3 ; int Defense = 3 ; int Health = 10 ; int Level = 1 ; for(;;) { char classChoice ; cin >> classChoice ; if( classChoice=='W' || classChoice=='w' ) { break ; …

Member Avatar for Ellisande
0
127
Member Avatar for Alex Edwards

a nontype template parameter can be a pointer or a reference to an object [B]with external linkage[/B]. the object itself need not be a constant. eg. [code=c++] struct A { explicit A( int ii=7 ) : i(ii) {} void modifier() { ++i ; } int i ; }; struct rtc …

Member Avatar for vijayan121
0
129
Member Avatar for Alex Edwards

does the term 'smart pointer' ring a bell? [url]http://www.informit.com/articles/article.aspx?p=31529[/url] [url]http://www.boost.org/doc/libs/1_35_0/libs/smart_ptr/smart_ptr.htm[/url] [url]http://en.wikipedia.org/wiki/Technical_Report_1#Smart_Pointers[/url] and why not use [ICODE]std::vector[/ICODE] as a container?

Member Avatar for vijayan121
0
102
Member Avatar for daviddoria

> I have a function [icode]double Min(vector<geom_Point3> &Points, int n);[/icode] > Then in another class, I have a private member: > [icode]vector<geom_Point3> Vertices_;[/icode] > and in a class function, I call: [icode]min_x = Min(Vertices_, 0);[/icode] > however, I get [icode]error: qualifiers dropped in binding reference...[/icode] > What does that mean?? …

Member Avatar for vijayan121
0
5K
Member Avatar for phalaris_trip

> ...139 files, with 16,000 lines of code... > ...So how do I start to disect messy code that is not documented and not written by me? > How does somebody look at code and start to make sense of it? ok. so you have about 70 components or so. …

Member Avatar for TacklesMcCaw
0
395
Member Avatar for cecyl

> I have to sort it much, much more quicker, are 10 seconds possible?. with 10 seconds at your disposal, you can sort it any which way you like. the fastest way would perhaps be to use [ICODE]std::partition[/ICODE] to move the most frequently occurring values (which are also the smallest …

Member Avatar for vijayan121
0
128
Member Avatar for daviddoria

> but I was wondering if anyone has this implemented? many people have. google for Moller-Trumbore algorithm. two other implementations: [url]http://jgt.akpeters.com/papers/Chirkov05/C2005.cpp.html[/url] (chirkov's c2005 algorithm) [url]http://geometryalgorithms.com/Archive/algorithm_0105/algorithm_0105.htm#intersect_RayTriangle([/url]) (sunday)

Member Avatar for Alex Edwards
0
223
Member Avatar for Flixter

[QUOTE]1. for all points p in S 2. for all points q in S 3. if p != q 4. draw a line from p to q 5. if all points in S except p and q lie to the left of the line add the directed vector pq to …

Member Avatar for Flixter
0
129
Member Avatar for himsymcpp

> dfference between Heap and free Store in C++ [url]http://www.devx.com/tips/Tip/13757[/url] [url]http://www.research.att.com/~bs/bs_faq2.html#realloc[/url] > const variables (i.e constants or literals get memory) , is there is separate area for them > or they are allocated in the data region only. they may not be allocated at all. as per the standard, [QUOTE]A …

Member Avatar for vijayan121
0
136
Member Avatar for ambarisha.kn

the C++ Standard Library doesn't provide any facility to compose function objects using logical connectives. (SGI STL does have the adapters compose1 and compose2; perhaps that is what you intended to use). such a facility is not planned for c++09 either; lambda functions and the bind library provide equivalent functionality …

Member Avatar for vijayan121
0
89
Member Avatar for henpecked1

> 3.6 * vector_a; why can I not implement this binary operator as a member operator of a class Vector? you can, if the class Vector is your own class. if not ( for example for standard containers ), you can overload this operator as a free function (not a …

Member Avatar for bugmenot
0
143
Member Avatar for kartik14

> Does extern "c" work only for C yes, and only with c capitalized. [ICODE]extern "C" ...[/ICODE] however, an implementation can support linkage to other languages. eg. [ICODE]extern "FORTRAN" ...[/ICODE] [QUOTE]7.5 - Linkage specifications [dcl.link] -2- The string-literal indicates the required language linkage. The meaning of the string-literal is implementation-defined. …

Member Avatar for vijayan121
0
147
Member Avatar for Agni

what is the default output locale on the machine? are you using something like [ICODE]hline( std::cout.widen( '-' ), n ) ;[/ICODE] or [ICODE]whline( window, std::cout.widen( '-' ), n ) ; [/ICODE] to draw these lines?

Member Avatar for Duoas
0
117
Member Avatar for wellibedamned

[code=c++]#include <iostream> #include <string> #include <sstream> template< typename T, std::size_t N > bool read_line_into_array( T (&array)[N], std::istream& istm ) { // returns true on success (line has exactly N items) // an alternative would be to return the number of items read std::string line ; if( std::getline( istm, line ) …

Member Avatar for vijayan121
0
87
Member Avatar for Alex Edwards

[ICODE]sortValues[/ICODE] is not a template member. you need to modify [ICODE]DO_SORT[/ICODE] [code] #define DO_SORT(varName, a, b, c, d) (*(varName)).sortValues(a, b, c, d) [/code] when you are sorting an array of [ICODE]char[/ICODE], use [ICODE]MySort<char>[/ICODE] not [ICODE]MySort<char*>[/ICODE] [CODE]//... MySort<char> *myCharSorter = new MySort<char>(); DO_SORT(myCharSorter, charPt, 0, 5, sortFunction); //...[/CODE] using all these …

Member Avatar for Alex Edwards
0
2K

The End.