learningcppisfun.blogspot.com
Learning C++: Accessing static members of a class
http://learningcppisfun.blogspot.com/2009/03/accessing-static-members-of-class.html
Sunday, March 01, 2009. Accessing static members of a class. Static members of a class are not associated with any one particular instance/object of it. They can even be accessed without any instance. The way to refer to them in your code is as shown below:. Static const std: string className;. Static const std: string& getClassName(). Std: cout Test: getClassName();. Std: cout testObject.getClassName();. July 22, 2011 at 8:15 AM. Subscribe to: Post Comments (Atom). New Delhi, Delhi, India. Remove duplic...
learningcppisfun.blogspot.com
Learning C++: Reading file all at once
http://learningcppisfun.blogspot.com/2008/02/reading-file-all-at-once.html
Sunday, February 17, 2008. Reading file all at once. Few times, you would want to read the whole file in one go, not line by line, not by a fixed buffer size. Here's a way to get that done:. Std: fstream ifs("filename.txt");. Std: stringstream oss;. As simple as that. The contents of the file are moved (re-directed) to the stringstream. The same code can be used to make copies of files. You would need to replace the stringstream object with an fstream one though. July 2, 2011 at 8:29 AM. Const in C and C.
learningcppisfun.blogspot.com
Learning C++: Remove duplicates from vector
http://learningcppisfun.blogspot.com/2008/04/remove-duplicates-from-vector.html
Sunday, April 13, 2008. Remove duplicates from vector. Q How do you remove duplicates from a vector? A This is how:. Void removeDuplicates(std: vector T and vec). Std: sort(vec.begin(), vec.end() ;. Vecerase(std: unique(vec.begin(), vec.end() , vec.end() ;. If I needed a container to keep itself populated of only unique values, I would probably choose std: set but then choosing the right container depends on so many other different factors as well. May 16, 2008 at 1:04 PM. CODE- - - -. Vecpush back(30); ...
learningcppisfun.blogspot.com
Learning C++: Copy constructor forms
http://learningcppisfun.blogspot.com/2008/04/copy-constructor-forms.html
Saturday, April 12, 2008. The copy constructor can have both forms(*) as below:. A(const A& rhs);. Both are perfectly valid and it is pretty easy to forget the 'const' for the rhs argument. The compiler accepts it as a perfectly valid syntax thinking that is what your intent was. But the above two are a bit different from each other. The first one rejects to work with/copy from parameters that are not const objects of type A as well as temporaries. So, if you tried something like this:. Const A const a;.
learningcppisfun.blogspot.com
Learning C++: const in C and C++
http://learningcppisfun.blogspot.com/2008/02/const-in-c-and-c.html
Sunday, February 17, 2008. Const in C and C. Globals are usually bad but not always. Consider C code that is to be migrated to C and has a bunch of global constants. As soon as that code is worked upon and is compiled as C , those const globals will cause the compiler to start emitting "undefined reference" or similar errors. This is because of fundamental different between how const is treated in C and C in the context of linkage. Subscribe to: Post Comments (Atom). New Delhi, Delhi, India. Reading file...
learningcppisfun.blogspot.com
Learning C++: Case insensitive string comparison
http://learningcppisfun.blogspot.com/2008/04/case-insensitive-string-comparison.html
Wednesday, April 16, 2008. Case insensitive string comparison. While looking up for case insensitive comparison function, I came across this nice article by Matt Austern : Case Insensitive String Comparison. And decided to try to make a sample that does that. Below is the result, am not sure if it is perfect and has no issues but that is the best I could do. Atleast, better than ignoring the locale completely! Used boost: bind due to buggy bind2nd. Using namespace std;. Using namespace std: tr1;. Std: tr...
learningcppisfun.blogspot.com
Learning C++: Extending enums
http://learningcppisfun.blogspot.com/2010/03/extending-enums.html
Saturday, March 27, 2010. There might come a scenario where you want to include an enum into a another one where the first one is a subset. Struct enum a {. End of enum a = d. Struct enum b : public enum a {. E = end of enum a 1,. Std: printf("enum a: a(%d), b(%d), c(%d), d(%d) n",. Enum b: a, enum b: b, enum b: c, enum b: d);. Std: printf("enum b: e(%d), f(%d), g(%d), h(%d) n",. Enum b: e, enum b: f, enum b: g, enum b: h);. Inheritance to the rescue. :-). Enum b: constant example = enum a: c;. Functors ...
learningcppisfun.blogspot.com
Learning C++: boost::tokenizer and BOOST_FOREACH
http://learningcppisfun.blogspot.com/2008/04/boosttokenizer-and-boostforeach.html
Saturday, April 19, 2008. Boost: tokenizer and BOOST FOREACH. I looked at the documentation. For what all could foreach macro support? The list didn't have boost tokenizer in it, which was expected but it said something that meant, it should work: "The support for STL containers is very general; anything that looks like an STL container counts. If it has nested iterator and const iterator types and begin() and end() member functions, BOOST FOREACH will automatically know how to iterate over it.". Boost: ...
learningcppisfun.blogspot.com
Learning C++: #pragma once standardized?
http://learningcppisfun.blogspot.com/2008/02/pragma-once-standardized.html
Sunday, February 17, 2008. I have at a few places, where people have mis-heard/mis-read that that #pragma once has been standardized for C 0x. It's "not". Even gcc has it labelled as an obsolete feature (for a couple of years now) - Obsolete once-only headers. I enjoy your blog very much. April 21, 2008 at 2:58 AM. Actually, if you read the link you posted you'd notice that while they don't *recommend* using it, it's been removed from the obsolete feature list as of GCC 3.4 (http:/ gcc.gnu.or...Case inse...
learningcppisfun.blogspot.com
Learning C++: comparing structs with memcmp
http://learningcppisfun.blogspot.com/2008/05/comparing-structs-with-memcmp.html
Saturday, May 03, 2008. Comparing structs with memcmp. Can you use memcmp to compare C style structs reliably? Let's first see what the C-standards has to say about the function: memcmp. From the C-standards, 7.21.4.1/The memcmp function:. 1 #include string.h. Int memcmp(const void *s1, const void *s2, size t n);. 2 The memcmp function compares the first n characters of the object pointed to by s1 to the first n characters of the object pointed to by s2.(248). Has definitely some padding - dont use memcmp.