2017-09-16 38 views
-4
#ifndef SALESITEM_H 
#define SALESITEM_H 
#include <iostream> 
#include <string> 
using namespace std; 
class Sales_data 
{ 
public: 
    Sales_data(unsigned num,int pr , string isb):units_sold(num),price(pr),isbn(isb) 
{ 
    cout<<"it works"<<endl; 
}; 
    Sales_data() = default; 
    Sales_data& combine(const Sales_data& rhs); 

    string Getisbn() ; 
    int Getprice() ; 
    unsigned Getunits_sold(); 


private: 
    unsigned units_sold; 
    int price; 
    string isbn; 
}; 
Sales_data& Sales_data::combine(const Sales_data& rhs) 
{ 
    units_sold += rhs.units_sold; 
    price += rhs.price; 
    return *this; 
} 
string Sales_data::Getisbn() 
{ 
    return isbn; 
} 
int Sales_data::Getprice() 
{ 
    return units_sold; 
} 
unsigned Sales_data::Getunits_sold() 
{ 
    return units_sold; 
} 
istream& read(istream& in,Sales_data &book) 
{ 
    in >>book.Getisbn(); 
    return in; 
} 

,它表明在日志无效操作数的二进制表示:

>> book.Getunits_sold(这个问题) /Users/apple/Desktop/shirley/shirley/Sales_item.h:185 :8:无效 操作数为二进制表达式( 'istream的'(又名 'basic_istream') 和 '字符串'(又名 'basic_string的, 分配>'))

+0

发布一个完整的示例,以便我们可以看到您的包含。我会猜测'#include '不是其中之一。 –

+0

#include 在标题 –

+1

呃,在你的例子中有一个'>>',它没有右边的字符串。你的例子中也没有185行,所以我会说他们错误是在你没有显示的代码中。不太确定你在“book.Getunits_sold();”中可能会做什么。 –

回答

0

我不知道为什么它说,有一个无效的操作r转换为二进制表达式(浮点型和浮点型)。非常感谢你!

int main(int argc, char** argv) { 

    float a; 
    float b; 

    b = a - (int) a; 

    printf("Write a number:"); 
    scanf("%f", &a); 

    if ((b == 0)&&(b % 2 == 0)) { 
     printf("It is an integer even number"); 
    } else if ((b == 0)&&(b % 2 != 0)) { 
     printf("It is an integer odd number"); 
    } else { 
     printf("It is a real number"); 
    } 

    return (EXIT_SUCCESS); 
} 
+0

这不提供问题的答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你将可以[对任何帖子发表评论](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提问者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/17666331) – purplepsycho

相关问题