-1

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.

  • 1
    For question 2 https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename – Cory Kramer Jun 23 '15 at 13:28
  • 1
    Voting to close this as question 1) alone is too broad. Other unrelated questions have duplicates as well. Since this isn't a chat room or forum, please try to focus on a specific question. – Drew Dormann Jun 23 '15 at 13:30
  • I am sorry if I made the question to broad. I will study the links provided . – user3577465 Jun 23 '15 at 13:48

1 Answers1

-6

For question 3, no need to make class name and file name the same, but you must keep cpp file and header file have the same name

kcbsbo
  • 1