前提・実現したいこと
macでvisual studioを使って以下のソースコードを実行したところ、エラーが発生します。
リンクがうまくできていないと思うのですが、解決方法を教えてください。
発生している問題・エラーメッセージ
Undefined symbols for architecture x86_64: "Tester::getBmi()", referenced from: _main in ccGsKks0.o "Tester::getName[abi:cxx11]()", referenced from: _main in ccGsKks0.o "Tester::Tester(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, double)", referenced from: _main in ccGsKks0.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status
該当のソースコード
Tester.h
c++
1class Tester{ 2 private: 3 string name; 4 double height; 5 double weight; 6 double bmi; 7 public: 8 double getBmi(); 9 string getName(); 10 Tester(string name,double height,double weight); 11};
Tester.cpp
C++
1#include <iostream> 2#include <string> 3using namespace std; 4#include "Tester.h" 5 6 7double Tester::getBmi(){ 8 if(this->bmi ==0){ 9 double mHeight = this->height/100; 10 this->bmi = this->weight/mHeight/mHeight; 11 } 12 return this->bmi; 13} 14string Tester::getName(){ 15 return this->name; 16} 17Tester::Tester(string name,double height,double weight){ 18 this->name = name; 19 this->height = height; 20 this->weight = weight; 21 this->bmi = 0; 22}
resp.cpp
C++
1#include <iostream> 2using namespace std; 3#include "Tester.h" 4 5 6int main(){ 7 Tester *ptr = new Tester("yamada", 170, 80); 8 cout << ptr->getName() << endl; 9 cout << ptr->getBmi() << endl; 10 delete ptr; 11 return 0; 12}
あなたの回答
tips
プレビュー