What's new

Argh GCC errors <warning LONG>

Cyberman

Moderator
Moderator
Ok I keep getting these anoying errors and I'm not exactly sure where they are coming from, I have several objects I am using it seems to be a problem of pass by value and pass by reference (not by a pointer but similar it's treated differently).

Errors
Code:
fighters.cpp: In member function `void Fighter::Show()':
fighters.cpp:46: no matching function for call to `Ball::Throw(Point)'
ball.hpp:16: candidates are: void Ball::Throw(Point&)
fighters.cpp:48: no matching function for call to `Ball::Throw(Point)'
ball.hpp:16: candidates are: void Ball::Throw(Point&)
fighters.cpp:81: no matching function for call to `Fighter::AimAt(Point)'
fighters.hpp:40: candidates are: u8 Fighter::AimAt(Point&)
fighters.cpp: In member function `u8 Fighter::AimAt(Point&)':
fighters.cpp:144: no matching function for call to `Fighter::WalkTo(Point)'
fighters.hpp:42: candidates are: void Fighter::WalkTo(Point&)
make: *** [fighters.o] Error 1

Headers
fighters.hpp
Code:
class Fighter : public Object
{
public:
    Fighter(Arena *);
    Fighter(Arena *,int);
    ~Fighter();
    u8 AimAt(Point &);
    Point FindNearest();
    void WalkTo(Point &);
    void Show(void);
    u16 Force;
    u32 Flags;
private:
    Point   Target;
    int Range;
    u16 Health;
    u8  State;
    u16  FrameP;
    Ball    *SBl;
};

ball.hpp
Code:
#ifndef _BALL_H_
#define _BALL_H_
#include "object.hpp"

class Ball : public Object
{
public:
    Ball(Arena *);
    Ball(Object *);
    ~Ball();
    void Show(void);             
    void Throw(Point &);       
private:
    Object  *MyHolder;  
    Point   M;     
};
#endif

objects.hpp
Code:
#ifndef _OBJECT_H_
#define _OBJECT_H_

#include "frame.hpp"
#include "geometry.hpp"
//#include "arena.hpp"

class   Arena;
class Object
{
public:
    Object(Arena *);
    Object(Arena *, Point &);
    Object(Arena *,Frame *);
    Object(Arena *,Frame *,  Point &); 
    ~Object();
    void Xlate( Point &);
    void Move( Point &);
    Point   At(void);
    void Show(void);
    Arena * MyArena;
    Point   Location;
    Frame *Graph;  
private:
    void ObjectInit(void);
    u8  Direction;  
    u8  Sprite;     
};
#endif

geometry.hpp
Code:
// 100 units is 1 meter
// this gives 21000km approximately as the greatest distance

class Point
{
public:
    Point();
    Point(int, int, int);
    Point( Point &);
    Point( Point *);
    ~Point() {;}
    
    Point operator+=(Point);
    //Point operator+(Point);
    Point operator*=(int);
    //Point operator*=(Point);
    Point operator/=(int);
    //Point operator*(int);
    //Point operator*(Point);
    //Point operator/(int);
    u8 operator==(Point);
    u8 operator!=(Point);
    int Diff(Point);
    int X, Y, Z;
};

// gravity is 9.81 m/s^2
extern Point   Gravity;
extern Point   Origin;

Offending code:
Code:
<46>                    SnowBall->Throw(Point(-Force, 0, 0));
<48>                    SnowBall->Throw(Point(Force, 0, 0));
<81>                    if (AimAt(FindNearest()))
<144>            WalkTo(Point(Location.X + abs(Diff), Location.Z + Diff, P.Y));
I assume the problem is that Throw() etc must be past by value instead of reference right? If I change this the compilor has a new set of things to bitch about.

Code:
fighters.cpp: In member function `void Fighter::Show()':
fighters.cpp:46: no matching function for call to `Point :: Point(Point)'
geometry.hpp:14: candidates are: Point :: Point(Point*)
geometry.hpp:13:                 Point:: Point(Point&)
fighters.cpp:46:   initializing argument 1 of `void Ball::Throw(Point)'
fighters.cpp:48: no matching function for call to `Point :: Point(Point)'
geometry.hpp:14: candidates are: Point :: Point(Point*)
geometry.hpp:13:                 Point :: Point(Point&)
fighters.cpp:48:   initializing argument 1 of `void Ball::Throw(Point)'
fighters.cpp:81: no matching function for call to `Point :: Point(Point)'
geometry.hpp:14: candidates are: Point :: Point(Point*)
geometry.hpp:13:                 Point :: Point(Point&)
fighters.cpp:81:   initializing argument 1 of `u8 Fighter::AimAt(Point)'
fighters.cpp: In member function `u8 Fighter::AimAt(Point)':
fighters.cpp:148: no matching function for call to `Point:: Point(Point)'
geometry.hpp:14: candidates are: Point :: Point(Point*)
geometry.hpp:13:                 Point :: Point(Point&)
fighters.cpp:148:   initializing argument 1 of `void Fighter::WalkTo(Point)'
make: *** [fighters.o] Error 1

What is the deal here.. Point(Point) I already used Point(int, int, int) to create the point, WTF is it looking for Point(Point). To be honest these errors make little sense unless I'm missing something.

Cyb
 
Last edited:

Hacktarux

Emulator Developer
Moderator
I'm not sure, but shouldn't it be like this :

Code:
<46>                    SnowBall->Throw(*(new Point(-Force, 0, 0)));
<48>                    SnowBall->Throw(*(new Point(Force, 0, 0)));
 

tooie

New member
I would be guessing your refrenceing a variable .. but you have not created a variable .. just trying to return a temp class .. is you took the param as
void Throw(Point);

it might not complain .. but you would be creating a complete structure copy in memory for the call .. other wise

Point pt(-Force, 0, 0);
SnowBall->Throw(pt);

Hack:
your method would probaly work .. but u would be leaking the memory if you did not delete the variables .. which I can not see how you could do since you do no record the values
 

Hacktarux

Emulator Developer
Moderator
do u have tried compiling with -felide-constructors ?
are u invoking the compiler using 'gcc' or 'g++' ? When you use gcc it can compile c++ code but it doesn't enable all c++ features as far as i remember.
 
OP
Cyberman

Cyberman

Moderator
Moderator
do u have tried compiling with -felide-constructors ?
are u invoking the compiler using 'gcc' or 'g++' ? When you use gcc it can compile c++ code but it doesn't enable all c++ features as far as i remember.
You know that might be the problem, however creating a variable of temporary scope and assigning to it or creating it with the right data seemed to fix the problem. I wonder if it's a problem of killer pointers? Main.c <- might be part of the problem since it's regular C :) hmmm. It's compiling now, I just need to add some object data and see if it works! :geek:

Cyb :saint:
 

Top