C++: Pimpl

Let’s say we defined this class inside a Reader.DLL DLL:

class DLLEXPORT Reader
    Reader(const std::string& filename);

    std::string ReadLine() const;
    bool        IsEndOfFile()    const;        

    FILE* file;

This class lets us read from a file once.
Continue reading “C++: Pimpl”

C++: The curiously recurring template pattern

Let’s consider the following class:

class Writer
    Writer() { }
    virtual ~Writer() { }

    virtual void write(const char* aStr) const = 0;

This class will be useful as the base class for implementing several specialized writers (a file writer and a console writer come to my mind right now), for instance:
Continue reading “C++: The curiously recurring template pattern”

C++: Inheritance on template specialization

When you implement something like:

/* 1 */ template <typename T> class MyClass { ... }; //template class for every T

/* 2 */ template <> class MyClass<char> { ... };  //template class full specialization for T=char

You are saying the C++ compiler: “Please, use the first template for all the MyClass<T> instances with any T except for the MyClass<T> instances where T = char”.
Continue reading “C++: Inheritance on template specialization”

C++: First message

#include <iostream>
#include <string>

using namespace std;

int main()
  string greeting = "Ifmmp!xpsme\"";
  for (string::const_iterator i = greeting.begin(); i != greeting.end(); ++i)
       cout << static_cast<char>((*i) - 1);
  cout << endl;
  return 0;

Hello, in this blog I want to publish some interesting information about C++ and other related topics (object oriented programming, generic programming, etc.); the idea is having this information useful and very accurate; so, since I am a fan of these topics but I am far from being an expert on them, I want you all to help me to improve the accuracy of every post I will write; therefore, your comments and suggestions will be really appreciated and will let me make the content of this blog better and better every day. Welcome and thank you for reading me.