Alex Rivera | Logout

What are the advantages and disadvantages of separating declaration and definition as in C++?

Asked 2009-03-14T11:18:21.680
12

In C++, declaration and definition of functions, variables and constants can be separated like so:

function someFunc();

function someFunc()
{
  //Implementation.
}

In fact, in the definition of classes, this is often the case. A class is usually declared with it's members in a .h file, and these are then defined in a corresponding .C file.

What are the advantages & disadvantages of this approach?

Edit
Report

1 Answer

1

One advantage that I haven't seen yet: API

Any library or 3rd party code that is NOT open source (i.e. proprietary) will not have their implementation along with the distribution. Most companies are just plain not comfortable with giving away source code. The easy solution, just distribute the class declarations and function signatures that allow use of the DLL.

Disclaimer: I'm not saying whether it's right, wrong, or justified, I'm just saying I've seen it a lot.

answered 2009-03-16T20:11:49.893

Your Answer