2016-09-11 42 views
-4

编译我的代码时收到一些错误。在成员函数错误C++

circleTypeImp.cpp: In member function âdouble circleType::getRadius() constâ: 
circleTypeImp.cpp:10: error: argument of type âdouble (circleType::)()constâ does not match âdoubleâ 
circleTypeImp.cpp: In member function âdouble circleType::setAreaCircle() constâ: 
circleTypeImp.cpp:15: error: invalid use of member (did you forget the â&â ?) 
circleTypeImp.cpp: In member function âdouble circleType::setCircumference() constâ: 
circleTypeImp.cpp:20: error: invalid use of member (did you forget the â&â ?) 
pointTypeImp.cpp: In member function âvoid pointType::setXCoordinate(double)â: 
pointTypeImp.cpp:9: error: âxâ was not declared in this scope 
pointTypeImp.cpp: In member function âvoid pointType::setYCoordinate(double)â: 
pointTypeImp.cpp:14: error: âyâ was not declared in this scope 
pointTypeImp.cpp: At global scope: 
pointTypeImp.cpp:23: error: prototype for âdouble pointType::getXCoordinate(double)â does not match any in class âpointTypeâ 
pointTypee.h:15: error: candidate is: double pointType::getXCoordinate() const 
pointTypeImp.cpp:28: error: prototype for âdouble pointType::getYCoordinate(double)â does not match any in class âpointTypeâ 
pointTypee.h:16: error: candidate is: double pointType::getYCoordinate() const 

我忽略了我的代码,我似乎无法看到它有什么问题。如果有人能指出我需要做什么,我会很感激。我不想找人为我做这件事,我只是需要一些帮助来解决它。

//main.cpp 

#include "pointTypee.h" 
#include "circleTypee.h" 
#include <iostream> 

using namespace std; 
int main() 
{ 
    pointType p; 
    circleType c; 

    double rad; 
    double area; 
    double circum; 


    double x; 
    double y; 

    cout << "Enter the x coordinate " << endl; 
    cin >> x; 
    cout << endl; 
    cout << "Enter the y coordinate " << endl; 
    cin >> y; 
    cout << endl; 
    cout << "The X & Y coordinates are: (" << x << "," << y << ")" << endl; 
    cout << "The area of the circle is: ";   //Add 
    cout << "The circumference of the circle is: "; //Add 

} 


//PointType.cpp 

#include "pointTypee.h" 
#include <string> 
#include <iostream> 

void pointType::setXCoordinate (double xcoord) 
{ 
    xcoord = x; 
} 

void pointType::setYCoordinate (double ycoord) 
{ 
    ycoord= y; 
} 

void pointType::print() const 
{ 
    cout << "The center point is at (" << xcoord << "," << ycoord << ")" << endl; 
    cout << endl; 
} 

double pointType::getXCoordinate(double xcoord) 
{ 
    return xcoord; 
} 

double pointType::getYCoordinate(double ycoord) 
{ 
    return ycoord; 
} 
pointType::pointType(double xcoord, double ycoord) 
{ 
    xcoord=0; 
    ycoord=0; 

} 



//pointType.h 

#ifndef POINTTYPEE_H 
#define POINTTYPEE_H 
#include <string> 

using namespace std; 

class pointType 
{ 
public: 
    void print() const; 
    void setXCoordinate(double xcoord); 
    void setYCoordinate(double ycoord); 
    double getXCoordinate() const; 
    double getYCoordinate() const; 
    pointType(void); 
    pointType(double xcoord, double ycoord); 
    ~pointType(void); 

private: 
    double xcoord; 
    double ycoord; 

}; 
#endif 


//circleType.h 

#ifndef CIRCLETYPEE_H 
#define CIRCLETYPEE_H 

#include "pointTypee.h" 

class circleType : public pointType 
{ 
public: 
    //circleType(double xcoord, double ycoord, double radius); 
    void print() const; 
    double setAreaCircle() const; 
    double setCircumference() const; 
    double getRadius() const; 
    circleType(double xcoord, double ycoord, double radius); 
    ~circleType(void); 
    circleType(); 
    //virtual ~circleType(); 

private: 
    double radius() const; 
    static double pie; 

}; 
#endif 



//circleTypeImp.cpp 

#include "circleTypee.h" 
#include "pointTypee.h" 
#include <string> 
#include <iostream> 

double circleType::getRadius()const 
{ 
    return radius; 
} 

double circleType::setAreaCircle() const 
{ 
    return 3.14 * radius * radius; 
} 

double circleType::setCircumference() const 
{ 
    return 3.14 * 2 * radius; 
} 

circleType::circleType() 
{ 
    //circleType::circleType(); 
} 

circleType::~circleType() 
{ 

} 

double pie = 3.14; 
+0

你为什么要分配给通过值传递的参数?而地狱是'getXCoordinate'等等呢?忘记它,一切都是错误的... – LogicStuff

回答

0

circleTypeImp.cpp: In member function âdouble circleType::getRadius() constâ:
circleTypeImp.cpp:10: error: argument of type âdouble (circleType::)()constâ does not match âdoubleâ

private: 
    double radius() const; 
//... 
return radius; 

您返回成员函数radius(),它返回一个双,但它不是一个双。我猜想,你想要一个成员double radius;

circleTypeImp.cpp: In member function âdouble circleType::setAreaCircle() constâ:
circleTypeImp.cpp:15: error: invalid use of member (did you forget the â&â ?)
circleTypeImp.cpp: In member function âdouble circleType::setCircumference() constâ:
circleTypeImp.cpp:20: error: invalid use of member (did you forget the â&â ?)

同样在这里,你可以使用成员函数radius(),这是不是双重。

pointTypeImp.cpp: In member function âvoid pointType::setXCoordinate(double)â:
pointTypeImp.cpp:9: error: âxâ was not declared in this scope
pointTypeImp.cpp: In member function âvoid pointType::setYCoordinate(double)â:
pointTypeImp.cpp:14: error: âyâ was not declared in this scope

void pointType::setXCoordinate (double xcoord) 
{ 
    xcoord = x; 
} 

void pointType::setYCoordinate (double ycoord) 
{ 
    ycoord= y; 
} 

错误说,它已经,既不x也不y声明。这应该是声明和定义

double pointType::getXCoordinate() const 
double pointType::getXCoordinate(double) 

pointTypeImp.cpp:28: error: prototype for âdouble pointType::getYCoordinate(double)â does not match any in class âpointTypeâ
pointTypee.h:16: error: candidate is: double pointType::getYCoordinate() const

同样在这里之间

void pointType::setXCoordinate (double x) 
//... 
void pointType::setYCoordinate (double y) 
//... 

pointTypeImp.cpp: At global scope:
pointTypeImp.cpp:23: error: prototype for âdouble pointType::getXCoordinate(double)â does not match any in class âpointTypeâ
pointTypee.h:15: error: candidate is: double pointType::getXCoordinate() const

不匹配。

+0

谢谢你的帮助 –