c ++编译器错误:体系结构x86_64的未定义符号:

时间:2016-09-19 01:58:48

标签: c++

我是c ++的新手,我试图实现一个基本的矩形类,它将宽度和高度作为参数并在x代码上打印出区域,现在当我尝试运行它时,构建失败,我得到了以下错误消息:

Undefined symbols for architecture x86_64:
  "Rectangle::Rectangle()", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我看了类似的答案,我不能让它适合我。任何的想法?感谢您的帮助。

//这里是Rectangle.hpp

#ifndef Rectangle_hpp
#define Rectangle_hpp
#include <stdio.h>

class Rectangle {

    public :
    int width,height;
    Rectangle();
    Rectangle (int a,int b);
    int area();
};


#endif /* Rectangle_hpp */

//这里是Rectangle.cpp

#include "Rectangle.hpp"
#include <iostream>
using namespace std;

Rectangle::Rectangle(int a, int b)

{
    width = a;
    height = b;
}

int Rectangle::area()

{
    return (width*height);
}

//这里是main.cpp

#include "Rectangle.hpp"
#include <iostream>
using namespace std;

int main() {
    Rectangle rect(3,4);
    Rectangle rectb;
    cout << "rect area: " << rect.area() << endl;
    cout << "rectb area: " << rectb.area() << endl;
    return 0;
}

0 个答案:

没有答案