Tag Archive for 'c++'

Interesting introduction to C++11

Wanna check what’s the whole buzz about C++11? Are you interested in what has changed comparing to the previous standards?

Herb Sutter wrote a great abstract with list of features of C++11 that give impression it’s a new language. In the article, there’s a link to the other useful resource, C++11 – the recently approved new ISO C++ standard (by Bjarne Stroustrup).

C++: Overriding methods – problem with hiding overloads in the base class

What is the outcome of the simple program below?

#include <iostream>
#include <conio.h>

using namespace std;

class Base 
{
public:
   void DoSth(int tmp) 
   {
	   cout < < "Base::DoSth(int)\n";
   }

   void DoSth(char tmp) 
   {
	   cout << "Base::DoSth(char)\n";
   }
};

class Derived : public Base
{
public:
   void DoSth(int tmp) 
   {
	   cout << "Derived:DoSth(int)\n";
   }
};

int main()
{
	Derived d;
	d.DoSth(5);
	d.DoSth('c');
   
	getch();
    return 0;
}

Continue reading 'C++: Overriding methods – problem with hiding overloads in the base class'

MFC: CButton and how ON_BN_DOUBLECLICKED message map works

Microsoft Foundation Classes (MFC) library provides CButton which, according to MSDN, can be used for creating a check box, a radio button, and a pushbutton.

There are two events CButton supports: (i) ON_BN_CLICKED (single click), (ii) ON_BN_DOUBLECLICKED (double click). Let’s assume you provide a meaningful implementation for a single click and do nothing in the event handler for the double click (empty method’s body). The result if a single click is obvious, but what will happen if user double clicks the check box (or the other CButton representation)? There are two possible answers (assuming the check box was unchecked initially):

  1. Check box will be checked, and then unchecked – a simulation of a double (single) click
  2. Check box will be checked only – one action takes place now

Continue reading ‘MFC: CButton and how ON_BN_DOUBLECLICKED message map works’

Initializer list and initializing derived class members

Initializer list in C++ looks like in the example below (see constructor od D class):

class B {
  public:
    B() { } 
};

class D : public B {
  public:
    int x;
    int y;

    D(int _x , int _y) : x(_x) , y(_y +1) { }
};

Continue reading ‘Initializer list and initializing derived class members’

C++: The Complete Reference

After several years of working with Java, C#, SQL and web technologies in general, there’s some time to use the other languages. Among others I’ll be writing some C++ code from time to time now.

I used C (and alittle bit of C++) when I was a student but that were all small projects and it was years ago. Now, it’s obvious I need to catch up with C/C++. I happened to get C++: The Complete Reference by Herbert Schildt. The word reference implies there’s probably no point in reading this book from title-page to colophon; there’s a lot of reference data like the standard function library. However, what I really liked about this book is it gives a quick introduction to most important aspects of C/C++ (e.g. pointers, classes, references, overloading, templates), of course with obvious and numerous code examples.

Recommended. It’s worth keeping this book nearby while working with C++.

 C++: The Complete Reference