Friday, November 29, 2013

GitHub for Windows Install Error

GitHub for Windows is a great tool for Windows users like me.;-) To Install GitHub for Windows you need dotNet version 4.0 or above.

Even having dotNet 4.0 you might face an issue while installing GitHub for Windows. I also had to face following common issue.

"Application cannot be started. Contact the application vendor."


To solve that issue go to run in Windows start menu and then go to following link.

C:\Users\[Your User Name]\AppData\Local\Apps

Then delete the 2.0 folder. It is ok that some files cannot be deleted from that folder.

Then try to re-install Github. Then you can proceed without an issue.

Friday, November 1, 2013

Using C++ classes

If you did your first OOP related coding using Java or C# you may find bit uncomfortable when you trying to use classes in C++. Because syntax and structure has bit difference between them. So lets see how to write a class in C++. This is a basic tutorial as there is no much explained tutorial in the web.

Unlike Java or C#, you have to define your class in the header file of C++ project. Now go to the header file of your project and add following class definition.

class Car
{
       private:
                int noOfTyres;

       public:
              Car();
               void drive();
};

As you can understand I'm going to discuss a simple example here. In the private: section you have to define private variables / methods of the particular class. In the public: section you can define public methods/variables of the class. The methods should not have its body with the header file. It will contain in the cpp file. Also if you are going to include a constructor other than the default constructor, it should declared at the public section.

Now go to the cpp file and include the header file using the #include tag. Now you have to add method body. Just check the following code.

You can define the constructor of the Car class,

Car::Car()
{
      // constructing code goes here
}

Explanation:
The first "Car" term and the double colons (::) describes that the method is belongs to the "Car" class. Next Car() term describes the Car constructor.

Now lets define the drive() method,

void Car::drive()
{
       // code goes here
}

Explanation,
The first "void" term describes the return type of the method. It should be same as what you gave at the header file. From the next phrases of the statement, it describes that the drive() method is belongs to the Car class.(Car::drive()).

So I hope you understood.

Now think you wanted to add a variable of another class type into the Car class. As an example "Type" class belongs to the "Car" class. Then your header file should be shown as below.

class Tyre
{
        private:
               // private things goes here
        public:
              // public things goes here
};

class Car
{
         private:
               Tyre tyres;
         public:
               void drive();  
};

The most important thing is that you have to declare the "Tyre" class before declaring "Car" class. It is a good practice to follow that the two class should keep in two header files.

I hope you got some basic idea of using Classes in C++.