Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : **** has not been declared

Tags:

c++

In my Function.h file:

class Function{
  public:
    Function();
    int help();
};

In my Function.cpp file:

#include "Function.h"
int Function::help() //Error here
{
  using namespace std;
  cout << "Help";
  return 1;
}

In my Main.cpp

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

int menu(){
  Function fc;
  fc.help();
  return 1;
}

int main(int args, char**argv){
  return menu();
}


Error is : ‘Function’ has not been declared
Can anybody tell me why? Thank you.

I tried like this and the problem is solved, but I dont really understand why:
In Function.h file:
I use

class Function{
  public:
    int status;
    Function():status(1){}
    int help();
};

instead of the old one

class Function{
  public:
    Function();
    int help();
};
like image 992
Xitrum Avatar asked Jul 12 '26 11:07

Xitrum


1 Answers

All your include statements are missing the #:

#include "Function.h"
^

Everything else looks fine, though you need to also #include <iostream> in Function.cpp since you're using cout.

Here is the Function.cpp that I got to compile and run:

#include "Function.h"
#include <iostream>

int Function::help() // No error here
{
    using namespace std;
    cout << "Help";
    return 1;
}

Function::Function()
{
}
like image 51
Cameron Avatar answered Jul 14 '26 23:07

Cameron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!