I wanted to write a simple program that uses classes but I've been running into errors. Anyone have a clue as to what is wrong with my code because I can't seem to figure it out.

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    using namespace std;

    class cone{
          private:
                double radius;
                double height;

          public:
          cone();
          void setvolume();//
          double conevol();
    };

    //implementation
    void cone(){
              double radius;
              double height;
     }

    void setvolume(double r,double h){
                      double radius=r;
                      double height=h;
    }

    double conevol(double r,double h){
           double vol=(1/3.0)*(3.14159265)*r*r*h;
           return vol;
    }      

    int main(){
        cone A;
        cout<<"The current volume of the cone is: "<<A.convol<<endl;
        A.setvolume(3.4,5.63);
        cout<<"The volume of the cone is now"<<A.conevol()<<endl;    
        system("PAUSE");
        return 0;
    }             

You need the class name before the method in the implementation. IE,

class cone
    {
          private:
                double radius;
                double height;
          public:
          cone();
          void setvolume(double r, double h);
          double conevol();
    };
    //implementation
    void cone::cone() : radius(0.0), height(0.0)
    {
    }
    void cone::setvolume(double r,double h)
    {
          radius=r;
          height=h;
    }
    double cone::conevol()
    {
           double vol=(1/3.0)*(3.14159265)*radius*radius*height;
           return vol;
    }

Note that I fixed a few other issues as well... :-)

Note that I fixed a few other issues as well... :-)

Oh really? Now Valgrind can't catch uninitialized value errors when somebody forgets to initialize the object with setvolume.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.