C++ undefined reference 에러
조회수 562회
main.cpp 나 Item.cpp 를 실행해보면 둘 다 undefined reference 에러가 뜨는데 초보라 여기서 더 이상 고칠수가 없네요. 무엇이 문제인지 알려주시면 정말 감사하겠습니다.
main.cpp
---------------
#include <iostream>
#include "Item.h"
int main(){
Item item1{ "Potato Chips", 1.78 };
Item item2{ "Doritos", 1.99, 2 };
std::cout << item1.get_name() << '\n';
std::cout << "Original " << item2.get_name() << '\n';;
std::cout << "Price: " << item2.get_price() << '\n';
item2.set_price(2.49);
std::cout << "Updated " << item2.get_name() << '\n';;
std::cout << "Price: " << item2.get_price() << '\n';
return 0;
}
Item.h
-----------
#ifndef ITEM_H
#define ITEM_H
#include <string>
class Item {
public:
Item(std::string name, double price, int quantity=1);
std::string get_name() const;
double get_price() const;
int get_quantity() const;
void set_price(double new_price);
void set_quantity(double new_quanity);
private:
std::string name;
double price;
int quantity;
};
#endif
Item.cpp
--------------
#include "Item.h"
#include <iostream>
using std::string;
Item::Item(std::string name, double price, int quantity){
this->name = name;
this->price = price;
this->quantity = quantity;}
string Item::get_name() const{
return name;
}
double Item::get_price() const{
return price;
}
int Item::get_quantity() const{
return quantity;
}
void Item::set_price(double new_price){
price = new_price;
}
void Item::set_quantity(double new_quanity){
price = new_quanity;
}
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
돌려 봤는데 에러도 없고 실행도 잘 됩니다.
코드 문제가 아니고 컴퓨터 또는 통합개발환경 문제 같습니다.
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력