Passing multi-dimensional arrays
August 18th, 2009 § 1 Comment
Today, a somewhat basic post.
Suppose you have a multi-dimensional array and would like to pass it to a function, but still be able to access it easily (by using row,col tuples for instance): passing the pointer is probably not the right way to go (although you could cast inside, but that’s ugly).
Implementing toString() and fromString() using std::stringstream
August 16th, 2009 § 1 Comment
The classes istringstream and ostringstream can be utilized to create generic templated toString() & fromString() functions. This functionality (which is built-in in many languages, such as Java) may come in very handy, quite often.
Destructors and placement new
August 16th, 2009 § 1 Comment
When using placement new operator, destruction isn’t as transparent as usual..
Changing the vtable pointer
August 14th, 2009 § Leave a Comment
Most compilers implement dynamic binding by using a vtable whose pointer resides at the beginning of each object’s memory footprint (something along the lines of [vtable-pointer|..members..], if we are not considering virtual inheritance).
Keeping this idea in mind, why don’t we go ahead and attempt to change that vtable pointer?
Printing using std::copy
August 14th, 2009 § Leave a Comment
From time to time we are required to print out a vector. It is possible to utilize the standard copy algorithm (std::copy) to do just that.