前提・実現したいこと
C++でcanvasを使い、車の絵を描きたいです。
以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
canvas.cppで undefined reference to '_imp_SelectObject undefined reference to '_imp_settext undefined reference to '_imp_に続く大量のエラー
該当のソースコード
C++
1//Point.h 2#include <string> 3#include <sstream> 4 5class Point{ 6public: 7 int x; 8 int y; 9 Point(int xp=0,int yp=0):x(xp),y(yp){} 10 std::string toString()const{ 11 std::stringstream ss; 12 ss<<"("<<x<<","<<y<<")"; 13 return ss.str(); 14 } 15}; 16/////////////////// 17 18//Body.h 19#ifndef BODY_H_ 20#define BODY_H_ 21 22#include "Point.h" 23#include "canvas/canvas.h" 24#include <string> 25 26class Body{ 27protected: 28 Point p; 29 int length; 30 int height; 31public: 32 Body(Point pp,int l,int h) 33 :p(Point(pp.x,pp.y)),length(l),height(h){} 34 void draw()const{ 35 canvas::setColor(0,0,0); 36 canvas::drawRectangle(p.x-length/2,p.y-height/2,length,height); 37 } 38}; 39///////////////////////// 40 41//Wheel.h 42#ifndef WHEEL_H_ 43#define WHEEL_H_ 44#include "Point.h" 45#include "canvas/canvas.h" 46 47class Wheel{ 48protected: 49 Point p; 50 int r; 51public: 52 Wheel(Point pp,int radius): 53 p(Point(pp.x,pp.y)),r(radius){} 54 void draw()const{ 55 canvas::setColor(0,0,0); 56 canvas::drawCircle(p.x,p.y,r); 57 } 58 void fill()const{ 59 canvas::setColor(0,0,0); 60 canvas::fillCircle(p.x,p.y,r); 61 } 62}; 63/////////////////////// 64 65//Car.h 66#ifndef CAR_H_ 67#define CAR_H_ 68#include "Body.h" 69#include "Wheel.h" 70#include "Point.h" 71 72 73class Car{ 74protected: 75 Point p; 76 Body body; 77 Wheel frontWheel; 78 Wheel rearWheel; 79public: 80 Car(int x,int y,int l,int h,int r): 81 p(Point(p.x,p.y)), 82 body(Body(Point(x,y),l,h)), 83 frontWheel( Wheel( Point(x+l/2-r,y+h/2),r)), 84 rearWheel(Wheel(Point(x-l/2+r,y+h/2),r)){} 85 86 void draw()const{ 87 body.draw(); 88 frontWheel.draw(); 89 rearWheel.draw(); 90 } 91}; 92#endif /* CAR_H_ */ 93/////////////////////////// 94 95//main.cpp 96#include "Car.h" 97#include "canvas/canvas.h" 98using namespace canvas; 99 100 101int main(){ 102 show(); 103 Car mycar(200,200,100,50,10); 104 mycar.draw(); 105 waitForKey(); 106}
補足情報(FW/ツールのバージョンなど)
Body.hは長方形の描写
Point.hは長方形の中心の座標
Wheel.hはタイヤ部分の描写
Car.hは車全体の描写
eclipse,ヘッダファイルやcppには全くエラーが出ません。
ただ #ifndef POINT_H
あ #define POINT_H
内容
あ #endif
(「あ」は気にしないでください)
と書いたらcanvasに大量のエラーが出ました。
それをなくすとPoint.hのclass Pointの部分にエラーが出ました。
previous definition of 'class Point'
redifinition of 'class Point'
の二つです
canvasはプログラムと同じフォルダに入っていて、canvasのフォルダに
canvas.hとcanvas.cppが入っています
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/03 04:41