Thread: draw function HELP!!!

  1. #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;
      }

  2. #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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Replies: 4
    Last Post: 11-23-2003, 07:15 AM