I recently switched to C++ after using Java for a good amount of time. However, I have some difficulty grasping the entire concepts of using header files along with class files.
Firstly, aren't headers just like interfaces in the OOP context?
Secondly if I have the following piece of code why do I get an error:
//CExample.h
//--START OF HEADER--
#ifndef CEXAMPLE_H
#define CEXAMPLE_H
#include <string>
class CExample{
private:
string name;
public:
CExample();
~CExample();
string getName();
};
#endif
//--End of Header--
//CExample.cpp
//--Start of class file--
#include "CExample.h"
string CExample::getName()
{
return name;
}
//--End of class file--
I get the error: 'string' does not name a type.
So as a summary of my confusion I have the following questions:
1) What's the best and healthy way of using includes in the headers.
2) What's the concrete difference between using "" and <> for includes. (Yes I have read plenty of c++ tutorials but the explanations are somewhat vague -- they say it depends on the directory location etc -- I would like some c++ veteran to make a clear statement if possible)
3)Are there are naming conventions enforced in C++? For example in Java, you need to have the class name match the file name in which is is defined.