0
subhasish's Avatar, Join Date: Mar 2006
Go4Expert Member
The compiler creates a default construtor only in the following situations:

* When the class's base class defines the default constructor.
* When the class of member objects defines default constructors.
* When the class has a virtual function.
* When the class has a virtual base class.

So for the following class, the compiler does not create a defalut constructor if you do not define one:

Code:
class test
{

	public:
		void show();
		void get(int, char*, float);
	private:
		int h,
		char* ch;
		float f;
};
0
subhasish's Avatar, Join Date: Mar 2006
Go4Expert Member
During the preprocessing phase, you can report errors by using the #error preprocessor directive. For example, suppose you have a program that uses 64-bit integers. This program has to be ported to various platforms. Since C++ doesn't define a standard 64-bit int type yet, each compiler uses a different type, and some compilers don't support 64-bit integers at all. A portable program can use the following preprocessor directives to make sure that the use of 64-bit integers is transparent to the target compiler. If the target compiler doesn't support 64-bit integers, the #error directive causes it to produce a diagnostic message that includes a user-supplied string and stops the compilation process:

Code:
 
#if defined((__BORLANDC__) || defined(__VISUALC32__)) 
#  define INT64 __int64 // then use the __int64 type
#elif defined(__GNUC__) // GCC doesn't support __int64
#  define INT64 long long // but uses 'long long' instead
#else
#  error “Unsupported platform; aborting”
#endif
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Comma-Separated Expressions
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by subhasish
The compiler creates a default construtor only in the following situations:
Default Constructors thread tells when a default constructor is not called.
0
0
sandesh's Avatar, Join Date: Sep 2007
Newbie Member
Hello.......
In the given code I want to use only one function pointer which can call two different type of function .............is it possible ................if yes then how ???


main()
{
// ( )(* fun_point)( );
int fun1(int,int);
char fun2(char,char);
}
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Offtopic comment:
sandesh, do not jump into any thread with your query or else you will not see any responses as the visibility of your query is very less. Try creating a new thread for your query if its not related to the thread you have posted into.
0
technosavvy's Avatar
Contributor
i think this is also a suitable tip which can be put in this thread..

always do comparision by putting the constant on the left hand side of the exspression.
e.g.
Code:
if (0 == toCompareVariable) {
/*anything*/
}
is a better programming practice than
Code:
if (toCompareVariable == 0) {
/*anything*/
}
this way even if someone do a typo and write if (0 = toCompareVariable) ..the compiler will produce an error on compilation itself..and thus we are not supposed to scratch our head finding where is code going wrong in case of if (toCompareVariable = 0)

Last edited by technosavvy; 14Jan2008 at 14:21..
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Thats a very good thing technosavvy to be doing when you are writing codes.
0
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
Quote:
Originally Posted by technosavvy

this way even if someone do a typo and write if (0 = toCompareVariable) ..the compiler will produce an error on compilation itself..and thus we are not supposed to scratch our head finding where is code going wrong in case of if (toCompareVariable = 0)

That's Excellent!!! We should take it as practice in our daily coding life to avoid some bugs.