Jos Timanta Tarigan wrote:
> Hi folks,
> Im new to C++ and currently developing C++ under os x. 
> 
> Im a little bit confused the difference between .h and .cpp. What is actually 
> a .h file? What is the difference between .h and .cpp? I actually implement 
> all my methods at .h file so my .h file look like this:
> 
> #include <iostream>
> 
> using namespace std;
> 
> class Person
> {
>       public:
>       Person::Person(string input)
>       {
>               userName = input;
>       }
> 
>       void Person::setFirstName(string input)
>       {
>               firstName = input;
>       }
>       private:
>               string userName;
> };
> 
> 
> Is there any convention/trade off with this method?
> 
> Thank you 
> 
> 
> Regards
> 
> Jos Timanta Tarigan

If you have two .cpp files that need to include the .h file and you plan 
on linking those two .cpp files together, the compiler will complain 
about duplicate definitions.

The only reason to define functions entirely in the header is for 
templates (typically a compiler limitation) or you use the 'inline' 
keyword.  Otherwise, put declarations in .h and definitions in .cpp.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to