![]() |
| | #1 |
| Registered User Join Date: Apr 2005
Posts: 10
| draw function HELP!!! also, I want to have the user input the values for x,y, z, and radius. I now that I have to put a cout asking for the values and cin to get the values in main or maybe I can use get. Can anyone give me an idea how to work this out. here is the code Code: #include <iostream>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#define PI 3.1415927
using namespace std;
class point
{
public:
point(const float xx, const float yy, const float zz) { x=xx; y=yy; z=zz; }
point(const point &p) { x = p.getX(); y = p.getY(); z = p.getZ(); }
point() { x = y = z = 0.0; }
float getX() const { return x; }
float getY() const { return y; }
float getZ() const { return z; }
private:
float x,y,z;
};
class shape3d
{
public:
shape3d(const point &pp) { p = pp; }
shape3d(const float x, const float y, const float z) { p = point(x,y,z); }
point getPoint() const { return p; }
virtual float getVolume() const = 0;
//virtual void draw( shape3d *todraw) const { todraw->draw(); }
private:
point p;
};
class sphere: public shape3d
{
public:
sphere(const point &p, const float r):shape3d(p) { radius = r; }
float getRadius() const { return radius; }
float getVolume() const { return 3.0*(PI*radius*radius*radius)/4.0; }
//error: draw function doesn't take 0 parameters
virtual void draw( sphere *todraw) const { todraw->draw(); }
private:
float radius;
};
main()
{
point p = point (0,0,0);
sphere s = sphere (p,50);
//error: draw function doesn't take 0 parameters
s.draw();
return 0;
}
|
| sunoflight77 is offline | |
| | #2 |
| Registered User Join Date: Mar 2005
Posts: 28
| I don't think you need "sphere * todraw" as an argument to the draw() function; take it out of the definition. Sorry, I'm being incoherent. I can't speak English at the moment, apparently; only C. Make the following changes: Code: virtual void draw( shape3d *todraw) const { todraw->draw(); };
should be
virtual void draw() const;
or
virtual void draw() const = 0; // (if you don't plan to ever implement a draw() routine for shape3d)
Code: virtual void draw( sphere *todraw) const { todraw->draw(); }
should be
virtual void draw() const {
// actual drawing code here
};
Code: void draw() {
draw();
};
|
| Orborde is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| doubt in c parser coding | akshara.sinha | C Programming | 4 | 12-23-2007 01:49 PM |
| Calling a Thread with a Function Pointer. | ScrollMaster | Windows Programming | 6 | 06-10-2006 08:56 AM |
| C++ compilation issues | Rupan | C++ Programming | 1 | 08-22-2005 05:45 AM |
| c++ linking problem for x11 | kron | Linux Programming | 1 | 11-19-2004 10:18 AM |
| Setting int pointers to one function (not using five functions!) | Marc Sharp | C Programming | 4 | 11-23-2003 07:15 AM |