Difference between " and < for #include preprocessor directive

#include preprocessor directive is used to include a header file in C++.
This tells the preprocessor to open the named header file and insert its contents where the #include statement appears. 
For #include may name a file in two ways: using angle brackets (< >) or in double quotes(").



File names in angle brackets, such as:
     #include

cause the preprocessor to search for the file in “include search path” that you specify in your environment or on the compiler command line.



File names in double quotes, such as:

    #include "header"
tell the preprocessor to search for the file in “current" directory. If the file is not found, then the include directive is reprocessed as if it had angle brackets instead of quotes.



Some services stop automatically if they have no work to do.

Sometimes it happens that you go and try to start any service and it gives you a nice message that "Some services stop automatically if they have no work to do.....".


There could be multiple reasons that this could happen..
1. The service crashed during startup.
2. Dependent service crashed/not started.
3. The service is not implemented properly.


In such scenario you can try following things:
1. Look at the event logs, if you find some error related to your service then try to resolve that.
2. Restart your machine in Safe mode, set the service properties as automatic and try to start the service. Sometimes this helps.
3. Try to completely uninstall and reinstall the service.

Private inheritance

The following code shows how we derive a class from other class.


class Base
{
   ...
}


class Derived: public Base
{
   ....
}


The Derived class is derived from Base with public level of inheritance. If you omit the public word while declaration such as 
class Derived : Base
the level of inheritance will be private.


The private inheritance is only supported in unmanaged C++. Its not supported in managed C++. if you declare the compiler will give error.

Encapsulation

Encapsulation is the process of combining data and functions into a single unit called class. Using the method of encapsulation, the programmer cannot directly access the data. 


Encapsulation clearly represents the ability to bundle related data and functionality within a single, autonomous entity called a class. 


Encapsulation helps by breaking a program down into small, self-contained entities.  



String cannot use this type here without a top-level '^'

If you are using String in unmanaged code with managed extension you should include it as


String^ str = "This is string";

Why static methods cant access non static members?

A static variable will be available for the entire lifetime of the program, even before the object of call is being created.  See below code

class CreditCard
{
public:
    static int noOfCards;
    …
};
int CreditCard::noOfCards = 99;
int _tmain(int argc, _TCHAR* argv[])
{
   Console::WriteLine("{0}", CreditCard::noOfCards); 
   // This line will print 99.
   ...
}

Same holds true for the static functions declared in a class, with the limitation that A static member function can only access static class members.  We will see why cant static member function cant access not static member data.

In the following code:

class CreditCard
{
public:
   static int GetnoOfCards()
   {
       return noOfCards;
   }
   ...
private:
   static int noOfCards;
};
int CreditCard::noOfCards = 99;
int _tmain(int argc, _TCHAR* argv[])
{
   Console::WriteLine("{0}", CreditCard::GetnoOfCards());
   // This line will print 99
   ...

}

Its clear that we can access the static member function without creating the object of a class. But for non static members object must be declared or constructor must get called to assign them memory, they needs to be initialized  before they get used. Hence static methods cannot access the non static members.

Fatal error C1190: managed targeted code requires a '/clr' option

In Visual Studio for C++ code you have two options, managed code or unmanaged code.

Managed code compiles to Intermediate Language that will run on the Common Language Runtime (CLR). Unmanaged code compiles to machine code that runs directly on the computer.

When you try to include any managed code in the unmanaged code and compile you will get this error message. 
To eliminate this error you should use the common runtime support for your code. 
To enable the /clr option for your project in Visual Studio go to:


Project --> Properties-->Configuration Properties-->General-->Common Language Runtime Support.


and select the "Common Language Runtime Support (/clr)". Now save and compile. 


.


Use of typedef

typedef is a user-defined synonym for an existing type. To create a synonym for a type, you use the keyword typedef followed by the name of the type and the new name you are defining.


E.g. typedef unsigned int uInt; 


Here uInt will be synonym for type unsigned int. 


The following line of code actually produces an int* which is and an int (not an int*) which is y. That is, the ‘*’ binds to the right, not the left.


int * x, y; 


However, if you use a typedef:



typedef int* intPtr;
intPtr x, y;
                  
Then both x and y are of type int*.

C++ Constants

Constants are named data-storage locations.  C++ has two types of constants: literal and symbolic. 
Literal constant is simply a value typed into the code. In following example 40 and Cat are the known as a literal constants.
E.g.
nCounter = 40;
strAnimalName = "Cat";

Symbolic constant is represented by a name.Its defined exactly the same way as a variable but the qualifier must start with the keyword const and the variable must be initialized.
E.g.
const int nMaxIterations = 49;
const unsigned long nMaxCharInFile = 123234;


Advantages of using Symbolic Constants:

  • The symbolic names make the program more readable.
  • It’s easier to change a single symbolic constant value than to find and replace all occurrences of a literal in a code.

What Is Object-Oriented Programming?

The Object Oriented Programming can be defined as type of programming where one can define not only the data type of a data structure, but also the types of operations (functions/methods) that can be applied to the data structure. 


The Object Oriented Programming mainly supports  features such as data abstraction, encapsulation, modularity, polymorphism, and inheritance. 

What is Android(OS)?

Android is a mobile operating system initially developed by Android Inc. Android is based upon a modified version of the Linux kernel.

Difference between UUID And SUUID

Universally Unique Identifier (UUID) is a identifier standard used in software construction, standardized by the Open Software Foundation (OSF).


The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. The use can be understand by means of example of firewall . The firewall assigns an UUID to every connection passing the firewall. This UUID is kept through all firewall operations. Therefore you can follow a connection through the firewall even if the packet content is NAT’ed. The UUID is also kept in the connection table entry for the connection.


Additionally there is the concept of an SUUID (Session UUID). For services which are using several connections (e.g. FTP) every connection has a unique UUID but the SUUID is equal for all the connections (it’s the same as the first/control connection’s UUID).'"

Conversion between 'CString' and 'BSTR'


BSTR (Basic string or binary string) is a string data type that is used by COM, Automation, and Interop functions. A BSTR is a composite data type that consists of a length prefix, a data string, and a terminator.

Use the AllocSysString member function of the CString to convert from CString to BSTR:

Code:
        CString cs("Hello");
        BSTR bstr = cs.AllocSysString();

Note: If you use the 'BSTR' by yourself, dont forget to call '::SysFreeString()' when you're done with it.

fatal error C1010 - unexpected end of file while looking for precompiled header directive

There are two ways to resolve the error:
1. Type following line at start of your code file 
   #include "stdafx.h" 


2. Select 'Not Using Precompiled Headers' options under the precompiler headers option in project propertied.


 Main reason behind this error is MFC Programs use many libraries, requiring the use of many header files. To save time, the compiler tries to precompile most of these header files, and use the predigested data instead of reading through all of these header files on every compilation. The standard method for MFC programs is to lump all of these common header file references into one header file ("stdafx.h"). If you just have to ask what "stdafx" means, it comes from the early name of MFC, which was AFX (application framework). 

When compiling each source (.cpp) file, the 
compiler skips through the source code, looking for the directive: 

#include "stdafx.h" 
Once it finds this directive, it substitutes the precompiled header information and then begins compiling the rest of the file. If your source file doesn't contain this directive, you get the error.

Golang: Http POST Request with JSON Body example

Go standard library comes with "net/http" package which has excellent support for HTTP Client and Server.   In order to post JSON ...