Jump to content


Need some help please


  • You cannot reply to this topic
3 replies to this topic

#1 bmonday87

    New Member

  • Members
  • Pip
  • 2 posts

Posted 29 September 2009 - 07:28 PM

im having trouble getting my program to work, i have sorting through errors for hours and am completely stumped, and odds are its going to be something really stupid. thanks in advance

Errors
animshapeO.h:28: error: cannot declare parameter '<anonymous>' to be of abstract type 'shapeO'
shapeO.h:3: note:   because the following virtual functions are pure within 'shapeO':
shapeO.h:9: note:       virtual bool shapeO::collidesWith(shapeO*)
p2.cpp: In function 'int main()':
p2.cpp:49: error: cannot allocate an object of abstract type 'animshapeO'
animshapeO.h:7: note:   because the following virtual functions are pure within 'animshapeO':
shapeO.h:9: note:       virtual bool shapeO::collidesWith(shapeO*)
p2.cpp:15: warning: unused variable 'w'
p2.cpp:15: warning: unused variable 'h'
animshapeO.h:28: error: cannot declare parameter '<anonymous>' to be of abstract type 'shapeO'
shapeO.h:3: note:   because the following virtual functions are pure within 'shapeO':
shapeO.h:9: note:       virtual bool shapeO::collidesWith(shapeO*)
animshapeO.cpp:21: error: cannot declare parameter 'shape' to be of abstract type 'shapeO'
shapeO.h:3: note:   since type 'shapeO' has pure virtual functions



animshape.cpp
#include "animshapeO.h"
#include "shapeO.h"
#include <iostream>
#include <stdlib.h>


void animshapeO::update(){

x = x + movex;
y = y + movey;

}
void animshapeO::setDirectionVector(){

movex = -5 + drand48() * 10;
movey = -5 + drand48() * 10;


}

bool animshapeO::collidesWith(shapeO  shape)
{

double rx,ry,rwidth,rheight;

shape.getRect(rx,ry,rwidth,rheight);

if (x+width > rx && x < rx+rwidth && x+height > rx && x < rx+ rheight)
        return true;
else
        return false;


return false;
}
-----------------------------------------------------------------------
animshapo.h
#ifndef animshapeO_H
#define animshapeO_H
#include "shapeO.h"


class animshapeO : public shapeO
{
private:
double x,y;
double movex, movey;


public:
animshapeO() : shapeO()
{

}
animshapeO(double X , double Y, double W, double H):shapeO()
{
shapeO::setRect(X,Y,W,H);

}

void update();

void setDirectionVector();

bool collidesWith(shapeO);
};
#endif
------------------------------------------------------------------------
shapeO.h
#ifndef SHAPEO_H
#define SHAPEO_H
class shapeO {
public:

        shapeO() {};
        virtual ~shapeO() {};

    virtual  bool collidesWith( shapeO *) = 0 ;
    void getRect(double & X, double & Y, double & W, double & H)
        {  X = x; Y = y; W = width; H = height; }
    void setRect(double X , double Y, double W, double H)
        { x = X; y = Y; width=W; height=H;}
protected:
    double x,y, height, width;
};
#endif


#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4969 posts
  • LocationBellevue, WA

Posted 29 September 2009 - 08:46 PM

BTW, you can use the [code]...[/code] tags to post code in the forum.

Anyway, your problem is that the collidesWith function is trying to take a shapeO passed by value, but you actually need it to be passed by reference. So, the collidesWith function should take either a pointer (shapeO *) or a reference (shapeO &). This needs to be updated in both shapeO and animshapeO.

BTW, perhaps the indentation got messed up in the paste to the forum, but if not, you should make an effort to indent/format your code more cleanly...it makes it much easier to read. ;)
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 bmonday87

    New Member

  • Members
  • Pip
  • 2 posts

Posted 29 September 2009 - 09:47 PM

Thanks alot

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4969 posts
  • LocationBellevue, WA

Posted 29 September 2009 - 09:55 PM

You shouldn't re-declare the variables in animshapeO. They already exist since you derived from shapeO. You can access them by name just like any other member variable; no special syntax needed.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users