C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-10-2005, 10:21 PM   #1
Registered User
 
Join Date: Apr 2005
Posts: 10
draw function HELP!!!

I am writing this program to draw a sphere, I am having problems with the draw function which is giving me an error(bold). Can anyone help me to write the draw function for this program.

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   Reply With Quote
Old 05-10-2005, 11:28 PM   #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)
Similarly,
Code:
virtual void draw( sphere *todraw) const { todraw->draw(); }
should be
virtual void draw() const {
     // actual drawing code here
};
You do not need to provide a member function of a class with a pointer to the class, assuming the member is working on that particular instance of the class and not some other, and you need to implement an actual draw() routine instead of
Code:
void draw() {
    draw();
};
which will crash/loop forever.
Orborde is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 01:49 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22