Tuesday, June 3, 2014

[C++]Characters Array

char **aPara;
    aPara = new char *[size];
    for(int i = 0; i < size; i++)
    {   
        aPara[i] = new char[40];
       aPara[i] = "Test";
        TRACE("Para %d : %s\n", i, aPara[i]);
    }

Tuesday, April 29, 2014

[C++] error lnk2019 unresolved external symbol

These kind of errors getting because of not implementing header defined functions. Therefore make sure you have implemented all functions defined in header.

Friday, April 25, 2014

[C++]Pure Virtual Functions

It's possible that you'd want to include a virtual function in a base class so that it may be redefined in a derived class to suit the objects of that class, but that there is no meaningful definition you could give for the function in the base class.

class Shape {
   protected:
      int width, height;
   public:
      Shape( int a=0, int b=0)
      {
         width = a;
         height = b;
      }
      // pure virtual function
      virtual int area() = 0;
};

The = 0 tells the compiler that the function has no body and above virtual function will be called pure virtual function.

[C++]Virtual Function

A virtual function is a function in a base class that is declared using the keyword virtual. Defining in a base class a virtual function, with another version in a derived class, signals to the compiler that we don't want static linkage for this function.

What we do want is the selection of the function to be called at any given point in the program to be based on the kind of object for which it is called. This sort of operation is referred to as dynamic linkage, or late binding.

[C++]Static members of a class

We can define class members static using static keyword. When we declare a member of a class as static it means no matter how many objects of the class are created, there is only one copy of the static member.
  • Static data is initialized to zero when the first object is created, if no other initialization is present.
  • Can't put it in the class definition but it can be initialized outside the class.
  • Use the scope resolution operator :: to identify which class it belongs to.
Example
#include 
 
using namespace std;

class Box
{
   public:
      static int objectCount;
      // Constructor definition
      Box(double l=2.0, double b=2.0, double h=2.0)
      {
         cout <<"Constructor called." << endl;
         length = l;
         breadth = b;
         height = h;
         // Increase every time object is created
         objectCount++;
      }
      double Volume()
      {
         return length * breadth * height;
      }
   private:
      double length;     // Length of a box
      double breadth;    // Breadth of a box
      double height;     // Height of a box
};

// Initialize static member of class Box
int Box::objectCount = 0;

int main(void)
{
   Box Box1(3.3, 1.2, 1.5);    // Declare box1
   Box Box2(8.5, 6.0, 2.0);    // Declare box2

   // Print total number of objects.
   cout << "Total objects: " << Box::objectCount << endl;

   return 0;
}

Output:
Constructor called.
Constructor called.
Total objects: 2

Thursday, April 3, 2014

[JAVA]Regular Expression

Splitting using regex (regular expression)
 String sData = "-rw-rw-r--+ 1 aime1 svrtech 83338 Apr 2 10:26 sat.log -rw-rw-r--+ 1 aime1 svrtech 2435 Apr 2 10:48 MAT.log -rw-rw-r--+ 1 aime1 svrtech 3470 Apr 2 08:35 ant_build.log ";

 String arrData[] = sData.split("(?<=.log )");

 for(String s : arrData){
        System.out.println(s);
 }
 Result:
-rw-rw-r--+ 1 aime1 svrtech 83338 Apr 2 10:26 sat.log 

-rw-rw-r--+ 1 aime1 svrtech 2435 Apr 2 10:48 MAT.log 

-rw-rw-r--+ 1 aime1 svrtech 3470 Apr 2 08:35 ant_build.log 
Further Reading: http://www.tutorialspoint.com/java/java_regular_expressions.htm

Window Messages

The operating system communicates with your application window by passing messages to it. A message is simply a numeric code that designates a particular event. For example, if the user presses the left mouse button, the window receives a message with the following message code.
#define WM_LBUTTONDOWN    0x0201
Some messages have data associated with them. For example, the WM_LBUTTONDOWN message includes the x-coordinate and y-coordinate of the mouse cursor. 
To pass a message to a window, the operating system calls the window procedure registered for that window.