简体   繁体   中英

Including class from header file in Eclipse C++

Very new to C++. I'm having trouble including a class and function from my header file into my cpp file. I've double checked everything and can't figure out what I'm doing wrong, maybe the format for eclipse is different from the guide I am following? If anyone can help it's very appreciated I've been stuck on this for a while.

I'm using the latest versions of Eclipse Indigo for C++ and MinGW

Below are my cpp and h files:

This is my .cpp file

#include <iostream>
#include "helloworldmodularized2.h"
using namespace std;



int  main()
{
    cat Earth;
    Earth.door_greeting();
}

Here is the .h file I am trying to include into my .cpp file

//helloworldmodularized2.h

#include <iostream>
using namespace std;

class cat
{
public:
    void door_greeting();
};

void cat::door_greeting()
{
    cout << "Hello World!\n";
    cout << "Hello Door!\n";
    cout << "Hello Cat!\n";
}

The .h file presents no errors

The errors I am getting when trying to build the .cpp file are:

'cat' was not declared in this scope Line 11

'Earth' was not declared in this scope Line 12

The code looks fine. Make sure the .h and .cpp are in the same directory.

Goto project properties

  1. under "c/c++ general" select "Paths and Symbols"
  2. in include tab select language like GNU C++
  3. click on Add
  4. check "is a workspace path"
  5. Click Workspace
  6. Under your project name select source folder "src"
  7. Apply and close

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM