| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4382 人关注过本帖
标题:error C2064: term does not evaluate to a function
只看楼主 加入收藏
稻草人25
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2016-4-20
结帖率:40%
收藏
已结贴  问题点数:20 回复次数:4 
error C2064: term does not evaluate to a function
#include<iostream>
#include<math.h>
using namespace std;
class Shape
{
public:
    virtual void ShapeName() const=0;
};
class Circle:public Shape
{
public:
    Circle(double r):radius(r){}
    double area(){return(3.14159*radius*radius);}
    virtual void ShapeName() const {cout<<"Circle:";}
    virtual void printArea();
protected:
    double radius;
};
void Circle::printArea()
{cout<<Circle::area()<<endl;}
class Rectangle:public Shape
{
public:
    Rectangle(float l,float w):length(l),width(w){}
    float area(){return length*width;}
    virtual void ShapeName() const {cout<<"Rectangle:";}
    void printArea();
protected:
    float length;
    float width;
};
void Rectangle::printArea()
{cout<<Rectangle::area()<<endl;}
class Triangle:public Shape
{
public:
    Triangle(float x=0,float y=0,float z=0);
    float area()
    {
        float p;
        p=(x+y+z)/2;
        return sqrt(p(p-x)(p-y)(p-z));
    }
    virtual void ShapeName() const {cout<<"Triangle:";}
    void printArea();
protected:
    float x;
    float y;
    float z;
};
void Triangle::printArea()
{cout<<Triangle::area()<<endl;}
int main()
{
    Circle a(2);
    Rectangle b(5,3.5);
    Triangle c(2,3,4);
    a.printArea();
    b.printArea();
    c.printArea();
    return 0;
}
出现2.cpp(42) : error C2064: term does not evaluate to a function如何解决
搜索更多相关主题的帖子: function include public double return 
2016-04-20 13:35
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:20 
直接说 return sqrt(p(p-x)(p-y)(p-z)) 这一句编译失败
return sqrt( p*(p-x)*(p-y)*(p-z) );
2016-04-20 13:46
稻草人25
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2016-4-20
收藏
得分:0 
回复 2楼 rjsp
谢谢  才发现
2016-04-20 14:32
稻草人25
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2016-4-20
收藏
得分:0 
回复 楼主 稻草人25
谢谢  程序上还有没有其他问题??
2016-04-21 12:05
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
回复 4楼 稻草人25
建议你找一本真正的C++书看看

先看main函数,也就是先决定怎么使用,后决定怎么实现
程序代码:
#include <iostream>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

class Shape
{
public:
    virtual const char* Name() const = 0;
    virtual double Area() const = 0;
protected:
    virtual std::ostream& output_( std::ostream& os ) const = 0;

    friend std::ostream& operator<<( std::ostream& os, const Shape& s );
};
std::ostream& operator<<( std::ostream& os, const Shape& s )
{
    return s.output_(os);
}

class Circle : public Shape
{
public:
    explicit Circle( double r ) : radius_(r)
    {
    }
    virtual const char* Name() const
    {
        return "Circle";
    }
    virtual double Area() const
    {
        return M_PI * radius_ * radius_;
    }
protected:
    double radius_;

protected:
    virtual std::ostream& output_( std::ostream& os ) const
    {
        return os << Name() << "(radius=" << radius_ << ") area=" << Area();
    }
};

class Rectangle : public Shape
{
public:
    Rectangle( double width, double height ) : width_(width), height_(height)
    {
    }
    virtual const char* Name() const
    {
        return "Rectangle";
    }
    virtual double Area() const
    {
        return width_*height_;
    }
protected:
    double width_;
    double height_;

protected:
    virtual std::ostream& output_( std::ostream& os ) const
    {
        return os << Name() << "(width=" << width_ << ", height=" << height_ << ") area=" << Area();
    }
};

#include <iostream>
using namespace std;

int main( void )
{
    Circle c( 2.0 );
    cout << c << endl;

    Rectangle r( 3.0, 4.0 );
    cout << r << endl;

    Shape& s1 = c;
    Shape& s2 = r;
    cout << s1 << '\n' << s2 << endl;

    return 0;
}

2016-04-21 16:12
快速回复:error C2064: term does not evaluate to a function
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033001 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved