1) A refrence should always be initialized when its declared.
2) A constant data member in the class should always be initialized in the Constructor of the class and not in the defnition of the class.
3) A static member of the class should also be defined once outside the class.
Eg: class A
{
public:
static int a;
A(){a=10;}
};
int main()
{
A b;
printf("%d", b.a);
return 0;
}
The above code will not compile successfully as static datamember of class A is not defined outside the class. "int A::a;" has to be added after the class Declaration.
4) Its leagal to call member functions from destructor of a Class, but care must be taken not to call functions which already have been freed. The called member functions should not lead to any exceptions being triggred as it will lead to calling the destructor of the class or this destructor itself might have been triggred by a Exception.
5) Static member functions of a class are actully Global functions with its namespace as the class.
6)If a forward declaration is made, but the function is never called, the program will compile and run fine. However, if a forward declaration is made, the function is called, but the program never defines the function, the program will compile okay, but the linker will complain that it can’t resolve the function call.
7)Angle brackets are used to including header files which came from the compiler and the quotes are used in including headers within the project
8) While C allows the main() function to return a void, C++ strictly about the return type of the main() and doesn't allow a void return type.
2) A constant data member in the class should always be initialized in the Constructor of the class and not in the defnition of the class.
3) A static member of the class should also be defined once outside the class.
Eg: class A
{
public:
static int a;
A(){a=10;}
};
int main()
{
A b;
printf("%d", b.a);
return 0;
}
The above code will not compile successfully as static datamember of class A is not defined outside the class. "int A::a;" has to be added after the class Declaration.
4) Its leagal to call member functions from destructor of a Class, but care must be taken not to call functions which already have been freed. The called member functions should not lead to any exceptions being triggred as it will lead to calling the destructor of the class or this destructor itself might have been triggred by a Exception.
5) Static member functions of a class are actully Global functions with its namespace as the class.
6)If a forward declaration is made, but the function is never called, the program will compile and run fine. However, if a forward declaration is made, the function is called, but the program never defines the function, the program will compile okay, but the linker will complain that it can’t resolve the function call.
7)Angle brackets are used to including header files which came from the compiler and the quotes are used in including headers within the project
8) While C allows the main() function to return a void, C++ strictly about the return type of the main() and doesn't allow a void return type.
No comments:
Post a Comment