我是C ++的新手,正在运行一个非常简单的文件。我有一个主文件和一个类(标头+ src文件)。但是,每当我运行它时,都会出现错误。
来源:
main.cpp
#include <iostream>
#include "Gui-Test/div.h"
using namespace std;
int main()
{
div computer;
cout << computer.divide();
return 0;
}
div.h
#ifndef DIV_H
#define DIV_H
class div
{
public:
div();
virtual ~div();
int divide();
protected:
private:
};
#endif // DIV_H
div.cpp
#include "Gui-Test/div.h"
div::div()
{
//ctor
}
div::~div()
{
//dtor
}
int div::divide()
{
return 6;
}
我正在使用Gnu Make对其进行编译,这在尝试将主文件编译为对象时出现以下错误
g++ -c src/main.cpp -o objects/main.o -I include
src/main.cpp: In function ‘int main()’:
src/main.cpp:8:9: error: expected ‘;’ before ‘computer’
div computer;
^~~~~~~~
src/main.cpp:8:17: error: statement cannot resolve address of overloaded function
div computer;
^
src/main.cpp:9:13: error: ‘computer’ was not declared in this scope
cout << computer.divide();
^~~~~~~~
Makefile:17: recipe for target 'objects/main.o' failed
make: *** [objects/main.o] Error 1
尝试了几件事,然后用它搜索了一下地狱,但是由于某种原因,我无法将其编译。
有人可以协助吗?