D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] C++ Questions?

 

At Mon 23 Mar 2009 20:19:01 UTC, Sam Grabham <sam@xxxxxxxxxxxxxxxxx> wrote:

> Have i miss understood how to use .h files with .cpp file work?

Yes.

> When searching the web i have found some users are putting all there
> code into the .h files.

Making all your functions inline in the .h file removes linking issues.

Firstly, in C++, the string type is "std::string", not just plain  
"string". It lives in the <string> header. The <cstring> header is  
entirely separate, and contains functions like strcpy for operating on  
C-style char* strings.

Secondly, in C++ you specify the type before the variable name. Your  
fileinfo.h should thus look like:

#ifndef FILEINFO_H
#define FILEINFO_H

#include <string>

// prototype
class fileInfo;
int fileProperties(std::string fileName);
bool IsDirectory(std::string);
bool RemoveDirectory(std::string);
#endif

 From looking at the .cpp file, it appears you expect the functions  
declared in the header to be member functions of your fileInfo class.  
As declared, they are not, they are "free" functions which are not  
members of any class.

At this point I suggest you buy yourself a copy of "Accelerated C++"  
by Koenig and Moo, published by Addison Wesley. It's currently 1/3 off  
at Amazon:  
http://www.amazon.co.uk/Accelerated-Practical-Programming-Example-Depth/dp/020170353X/

Anthony
-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams
just::thread C++0x thread library   | http://www.stdthread.co.uk
Custom Software Development         | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK



-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html