尝试使用类方法打印对象内容。继续获取“错误:语句无法解析过载功能的地址”。
初学者在这里,我正在为课程进行作业,在研究该计划时,我遇到了一些麻烦。我无法弄清楚如何使用与我制作的类不同的方法来打印我在主要方法中拥有的对象中的内容。
这是我的代码:
#include <iostream>
using namespace std;
class Book {
private:
string title;
int pages;
double price;
public:
Book () {
title = "";
pages = 0;
price = 0.0;
}
Book(string t, int p, double pr) {
title = t;
pages = p;
price = pr;
}
void setPrice(double);
void getBookInfo(Book, Book);
};
void Book::setPrice(double pr) {
price = pr;
}
void Book::getBookInfo(Book b1, Book b2) {
cout << b1.title << b1.pages << b1.price << endl;
cout << b2.title << b2.pages << b2.price << endl;
}
int main() {
Book b1("C++ Programming", 802, 90.55);
Book b2("Chemistry Tests", 303, 61.23);
b2.setPrice(77.22);
b1.getBookInfo;
b2.getBookInfo;
return 0;
}
我需要使用 b1 和 b2 b2 的内容使用 getbookinfo()方法,但是每次我认为我知道我在做什么,我会在 b1.getbookinfo 和 b2.getBookinfo
。它是我自己的,因此输出并没有全部束缚在一起,但我什至无法让它输出任何东西!
这是我第一次与课堂和构造师一起工作,所以我现在真的迷失了方向。帮助您表示赞赏!谢谢!
beginner here, I am working on an assignment for a course and while working on this program, I am experiencing some troubles. I cannot figure out how to print out the contents within an object I have in my main method using a different method from a class I made.
Here's my code:
#include <iostream>
using namespace std;
class Book {
private:
string title;
int pages;
double price;
public:
Book () {
title = "";
pages = 0;
price = 0.0;
}
Book(string t, int p, double pr) {
title = t;
pages = p;
price = pr;
}
void setPrice(double);
void getBookInfo(Book, Book);
};
void Book::setPrice(double pr) {
price = pr;
}
void Book::getBookInfo(Book b1, Book b2) {
cout << b1.title << b1.pages << b1.price << endl;
cout << b2.title << b2.pages << b2.price << endl;
}
int main() {
Book b1("C++ Programming", 802, 90.55);
Book b2("Chemistry Tests", 303, 61.23);
b2.setPrice(77.22);
b1.getBookInfo;
b2.getBookInfo;
return 0;
}
I need to print out the contents of Book b1 and Book b2 using the getBookInfo() method, but every time I think I know what I'm doing, I get "error: statement cannot resolve address of overloaded function" on b1.getBookInfo and b2.getBookInfo.
Of course, I will format it on my own so the output isn't all bunched together, but I can't even get it to output anything!
This is my first time working with class and constructors, so I am really kinda lost right now. Help is appreciated! Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误来自这里:
您正在尝试调用类的方法,但没有使用呼叫操作员
()
,因此您正在加载方法的地址。要解决此错误,请使用呼叫操作员来调用方法:除了您的代码有很多错误,但您表示您是初学者,所以这并不罕见
The error is coming from here:
you are trying to call methods of a class but didn't use the call operator
()
so you are instead loading the address of the method. To solve this error use the call operator to call the methods:beside that your code has many faults but you indicated you are a beginner so this isn't unusual