Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Search the Tips
Tip Bank > C++ > Functions

Functions - Page 3

41-60 of 109     Previous     Next
Returning a Value from a Function that Throws
by Danny Kalev
A reader asked me the following questions: "Can a function that returns something, throw a exception and still return a value?" Lets' look at a concrete ...
Old-style Function Declarations
by Danny Kalev
In earlier stages of C, function declarations looked like ...
Factorial Function
by Danny Kalev
One of the classic examples of using recursion is calculating a factorial of a number. Here's a typical implementation of this ...
Don't Use const for Passing Parameters by Value
by Danny Kalev
To avoid undesirable changes to an argument passed by reference, you pass it as a const parameter. For ...
Invoking a Function Through a Pointer
by Danny Kalev
When you call a function through a pointer to function, use that pointer as if it were the function itself, not a pointer. For ...
Defining a Function with the 'friend' in a .cpp
by DevX Pro
With the following: friend int operator == (const cs303Point& point0, const cs303Point& point1); in my .h file, how should the first line of the function definition look in the .cpp file?
Base Virtual Function To Determine Overridden Functions
by DevX Pro
I am using VC++ 5.0, and have a base class with several virtual functions. The derived class may/may not implement the function. If it does, it first calls the base function explicitly and then continues with any custom code. The base function is opening a socket for communication, leaving it open, and the derived function will continue to use the channel. If there isn't an implemented derived function, the base is getting called directly and leaving the socket open. I would like to know if there is a way that the base function can inspect the "this" pointer to determine if its associated object has an overriding function, and if not close the connection. Aside from the C++ morality issue, I want to implement this in the base class so that the numerous derived classes are kept simple.
Returning Aggregates from a Function
by Danny Kalev
Both C and C++ allow you to return by value aggregates, e.g., structs and unions, from a function. However, the runtime overhead of returning large objects by value can be significant. This is why ...
The standard functions isalpha(), isdigit(), isprint() etc., defined in the stan
by Danny Kalev
The .* and ->* operators enable you to call a member function without having to know the function's name. Remember, however, that when using these operators, you have to parenthesize the expression ...
Understanding Stack Overflow
by Danny Kalev
The stack is a region of memory on which local automatic variables are created and function arguments are passed. The implementation allocates a default stack size per process. On modern operating ...
Avoid Redundant Inline Declarations
by Danny Kalev
Remember that functions defined inside the class definition are implicitly inline. Therefore, the inline keyword is redundant in the definition of the member function of the following ...
Invoking Overloaded Operators Explicitly
by Danny Kalev
The overloaded operator mechanism is "syntactic sugar" for ordinary function calls. You can always use the explicit name of an overloaded operator function to resolve ambiguities or document your ...
Functions Are Extern by Default
by Danny Kalev
Unless explicitly declared static, an ordinary function is implicitly declared extern in C and C++. For ...
The pow() Function
by Danny Kalev
The Standard Library provides the pow() functions (declared in <math.h>) which takes two arguments of type double, x and y: double powl(double x, double ...
The calloc() Function
by Danny Kalev
The standard C library declares the function calloc() in as ...
Renaming a File
by Danny Kalev
To rename a file, use the standard function rename() (declared in <stdio.h>). This function takes two arguments of type const char *, the first of which is the old name and the second one is the ...
Re-entrant Functions
by Danny Kalev
A function that can be safely called while it's already executing is said to be re-entrant. The C++ standard doesn't state whether the Standard Library's functions are re-entrant; this is an ...
Making Inline Functions Compatible With C Compilers
by Danny Kalev
A global function may be declared inline. If you use the same function in different development environments, e.g., C and C++, you can hide the "inline" keyword from a C compiler while keeping it ...
Differences Between C and C++ in the Prototypes of Standard Functions
by Danny Kalev
A small number of functions from the Standard Library have different signatures on C and C++. These functions are: strchr(), strpbrk(), strrchr(), strstr(), and memchr() as well as their ...
Avoid Obsolete Win16 Memory Functions
by Danny Kalev
The 16-bit operating systems Windows 3.1x and DOS had a very intricate memory model that required the use of functions like GlobalAlloc() and GlobalLock(). These functions addressed a specific ...
41-60 of 109     Previous     Next
Thanks for your registration, follow us on our social networks to keep up-to-date