c++:没有重载函数的实例?
// stock.h
#ifndef STOCK_H
#define STOCK_H
// declare Stock Class
class Stock
{
private:
string StockExchange;
string Symbol;
string Company;
double Price;
int Shares;
public:
Stock();
Stock(string stockExchange, string symbol, string company, double price, int shares);
void displayStockInfo();
void setStockInfo(string stockExchange, string symbol, string company, double price, int shares);
double getValue();
bool operator < (Stock & aStock);
bool Stock::operator > (Stock & aStock);
};
#endif
[break]
//main.cpp
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include "stock.h"
using std::string;
using std::endl;
using std::cout;
using std::setw;
using std::ifstream;
// *******************************
// Stock class
Stock::Stock() {
StockExchange = "";
Symbol = "";
Company = "";
Price = 0.0;
Shares = 0;
}
Stock::Stock(string stockExchange, string symbol, string company, double price, int shares) {
StockExchange = stockExchange;
Symbol = symbol;
Company = company;
Price = price;
Shares = shares;
}
// end Stock class
// *******************************
...
我的错误说的是“不存在重载函数 Stock::Stock(string stockExchange, string symbol, string company, doubleprice, int Shares) 的实例”。
我做错了什么?我在头文件中看到它。
// stock.h
#ifndef STOCK_H
#define STOCK_H
// declare Stock Class
class Stock
{
private:
string StockExchange;
string Symbol;
string Company;
double Price;
int Shares;
public:
Stock();
Stock(string stockExchange, string symbol, string company, double price, int shares);
void displayStockInfo();
void setStockInfo(string stockExchange, string symbol, string company, double price, int shares);
double getValue();
bool operator < (Stock & aStock);
bool Stock::operator > (Stock & aStock);
};
#endif
[break]
//main.cpp
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include "stock.h"
using std::string;
using std::endl;
using std::cout;
using std::setw;
using std::ifstream;
// *******************************
// Stock class
Stock::Stock() {
StockExchange = "";
Symbol = "";
Company = "";
Price = 0.0;
Shares = 0;
}
Stock::Stock(string stockExchange, string symbol, string company, double price, int shares) {
StockExchange = stockExchange;
Symbol = symbol;
Company = company;
Price = price;
Shares = shares;
}
// end Stock class
// *******************************
...
My error says something along the lines of "no instance of overloaded function Stock::Stock(string stockExchange, string symbol, string company, double price, int shares) exists."
What am I doing wrong? I see it in my header file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尚未在
stock.h
头文件中包含
头文件,即使您在它。也许这就是导致此错误消息的原因(如果是这种情况,那么我会说这确实是一个坏消息)。另一个问题是,在
Stock
类定义中,您这样写:这是错误的。从中删除
Stock::
,并使其像这样:在类外部定义函数时需要
Stock::
。You've not included
<string>
header file instock.h
header file, even though you're usingstd::string
in it. Maybe that is causing this error message (if that is the case, then I would say its really a bad message).Another problem is that in
Stock
class definition, you've written this:which is wrong. Remove
Stock::
from it, and make it like this:Stock::
is required when defining the function outside the class.