About Monkey 2 › Forums › Monkey 2 Programming Help › Fail to compile
This topic contains 4 replies, has 3 voices, and was last updated by 
 Jesse
 2 years, 9 months ago.
- 
		AuthorPosts
 - 
		
			
				
July 5, 2016 at 5:57 pm #1759
I can’t figure this error out. The code translate with out problems but when it compiles, the c compiler complains about an error:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134Function Main()Local v1:Collision = New HitBox(new PVector2D(7,56),30,40,50,48)Local v2:Collision = New HitCircle(new PVector2D(28,17),10,15,20)v1.Render()v2.Render()End functionClass PVector2DField x:FloatField y:FloatMethod New()End MethodMethod New(x:Float,y:Float)Self.x = xSelf.y = yEnd MethodMethod Set:Void(x:Float,y:Float)Self.x = xSelf.y = yEnd MethodEnd ClassClass Collision AbstractField pos:PVector2DField off:PVector2DMethod New()off = New PVector2DEnd MethodMethod Set:Void(pos:PVector2D,ox:Float,oy:Float,width:Float,height:Float) AbstractMethod Set:Void(pos:PVector2D,ox:Float,oy:Float,radius:Float) AbstractMethod Collided:Bool(col:Collision) AbstractMethod Render() AbstractEnd ClassClass HitBox Extends CollisionField width:FloatField height:FloatMethod New()End MethodMethod New(p:PVector2D,x:Float,y:Float,width:Float,height:Float)Set(p,x,y,width,height)End MethodMethod Set:Void(pos:PVector2D,ox:Float,oy:Float,width:float,height:float) OverrideSelf.pos = posoff.Set(ox,oy)Self.width = widthSelf.height = heightEnd MethodMethod Collided:Bool(bx:Collision) OverrideLocal box := cast<HitBox>(bx)Local b1x1:Float = pos.x + off.xLocal b1y1:Float = pos.y + off.yLocal b1x2:Float = pos.x + widthLocal b1y2:Float = pos.y + heightLocal b2x1:Float = box.pos.x + box.off.xLocal b2y1:Float = box.pos.y + box.off.yLocal b2x2:Float = box.pos.x + box.widthLocal b2y2:Float = box.pos.y + box.heightIf b1x1 > b2x2 Return FalseIf b1x2 < b2x1 Return FalseIf b1y1 > b2y2 Return FalseIf b1y2 < b2y1 Return FalseReturn TrueEnd MethodMethod Render:Void() OverridePrint pos.yEnd MethodEnd ClassClass HitCircle Extends CollisionField radius:FloatMethod New(pos:PVector2D,ox:Float,oy:Float,radius:Float)Set(pos,ox,oy,radius)End MethodMethod Set(pos:PVector2D,ox:Float,oy:Float,radius:Float=0) OverrideSelf.pos = posoff.Set(ox,oy)Self.radius = radiusEnd MethodMethod Collided:Bool(bx:Collision) OverrideLocal box := Cast<HitBox>(bx)If box Then Return Rectangle(box)Local cir := Cast<HitCircle>(bx)If cir Then Return Circle(cir)Return FalseEnd MethodMethod Circle:Bool(cir:HitCircle)Local totRadius:FloatLocal vx:Float = pos.x - cir.pos.xLocal vy:Float = pos.y - cir.pos.ytotRadius = Self.radius+cir.radiusIf (vx*vx+vy*vy) < totRadius*totRadius Return TrueReturn falseEnd MethodMethod Rectangle:Bool(rect:HitBox)Local vx:Float = rect.width/2Local vy:Float = rect.height/2Local radius:Float = Sqrt(vx*vx + vy*vy)Local totRadius := Self.radius + radiusLocal nx:Float = pos.x - rect.pos.xLocal ny:Float = pos.y - rect.pos.yIf totRadius*totRadius < (nx*nx + ny*ny) Return FalseReturn TrueEnd MethodMethod Render:void() OverridePrint pos.xEnd MethodEnd Classit translate fine but when it compiles the c compiler complains and gives me an error:
<quote>
mx2cc version 1.0.0
***** Building app ‘/Users/legend/Desktop/monkeypatrol/src/testlist.monkey2’ *****
Parsing…
Semanting…
Translating…
Compiling….
Build error: System command ‘g++ -std=c++11 -Wno-deprecated-declarations -Wno-tautological-pointer-compare -Wno-undefined-bool-conversion -Wno-int-to-void-pointer-cast -Wno-inconsistent-missing-override -Wno-logical-op-parentheses -Wno-parentheses-equality -O0 -I”/Users/legend/monkey2/modules/monkey/native” -c -o “/Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_0testlist.cpp.o” “/Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.cpp”‘ failed.g++ -std=c++11 -Wno-deprecated-declarations -Wno-tautological-pointer-compare -Wno-undefined-bool-conversion -Wno-int-to-void-pointer-cast -Wno-inconsistent-missing-override -Wno-logical-op-parentheses -Wno-parentheses-equality -O0 -I”/Users/legend/monkey2/modules/monkey/native” -c -o “/Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_0testlist.cpp.o” “/Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.cpp”
In file included from /Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.cpp:2:
In file included from /Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.h:5:
In file included from /Users/legend/monkey2/modules/monkey/native/bbmonkey.h:13:
/Users/legend/monkey2/modules/monkey/native/bbobject.h:48:11: error: allocating an object of abstract class type ‘t_default_HitBox’
T *p=new T( a… );
^
/Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.cpp:26:35: note: in instantiation of function template specialization ‘bbGCNew<t_default_HitBox, t_default_PVector2D *, float, float, float, float>’ requested here
f0.l_v1=((t_default_Collision*)(bbGCNew<t_default_HitBox>(f0.t0=bbGCNew<t_default_PVector2D>(7.0f,56.0f),30.0f,40.0f,50.0f,48.0f)));
^
/Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.h:48:16: note: unimplemented pure virtual method ‘m_Set’ in ‘t_default_HitBox’
virtual void m_Set(t_default_PVector2D* l_pos,bbFloat l_ox,bbFloat l_oy,bbFloat l_radius)=0;
^
In file included from /Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.cpp:2:
In file included from /Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.h:5:
In file included from /Users/legend/monkey2/modules/monkey/native/bbmonkey.h:13:
/Users/legend/monkey2/modules/monkey/native/bbobject.h:48:11: error: allocating an object of abstract class type ‘t_default_HitCircle’
T *p=new T( a… );
^
/Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.cpp:29:35: note: in instantiation of function template specialization ‘bbGCNew<t_default_HitCircle, t_default_PVector2D *, float, float, float>’ requested here
f0.l_v2=((t_default_Collision*)(bbGCNew<t_default_HitCircle>(f0.t0=bbGCNew<t_default_PVector2D>(28.0f,17.0f),10.0f,15.0f,20.0f)));
^
/Users/legend/Desktop/monkeypatrol/src/testlist.buildv1.0.0/build_cache/desktop_debug_macos/testlist_testlist.h:49:16: note: unimplemented pure virtual method ‘m_Set’ in ‘t_default_HitCircle’
virtual void m_Set(t_default_PVector2D* l_pos,bbFloat l_ox,bbFloat l_oy,bbFloat l_width,bbFloat l_height)=0;
^
2 errors generated.
***** Fatal mx2cc error *****Build error.
</quote>
July 5, 2016 at 11:12 pm #1769Don’t you have to implement every one of those abstract methods in (both of) those inherited classes?
Random pick from a google search:
“abstract classes are used to enforce methods that need to be overridden in the derived classes, thus avoiding potential runtime errors.”
July 5, 2016 at 11:37 pm #1770Thanks Olejr! that appeared to have solved it.
My question now is. Shouldn’t monkey be able to detect that?
July 6, 2016 at 12:06 am #1771Yes MX2 should have detected that – raise a bug over on GitHub
July 6, 2016 at 2:59 am #1774Will do. Thanks.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.