菜鸟请教 (5)
时间:2011-12-04
来源:互联网
大神 帮帮忙把 看看怎么错了
我是有个Product类,我想在storage类中动态添加Product类的对象,所以用了vector然后就各种错误 ,请大神帮看看,先奉上代码
Product.h
#include <iostream>
using namespace std;
class Product
{
public:
string time1;
string name;
double price;
string kind;
public:
Product(string time,string name,double price,string kind);
string getTime();
string getName();
double getPrice();
string getKind();
};
Product.cpp
#include "Product.h"
Product::Product(string Time1,string Name,double Price,string Kind)
{
time1=Time1;
name=Name;
price=Price;
kind=Kind;
}
string Product::getTime()
{
return time1;
}
string Product::getName()
{
return name;
}
double Product::getPrice()
{
return price;
}
string Product::getKind()
{
return kind;
}
storage.h
#include <iostream>
#include "Product.h"
#include<vector>
using namespace std;
class storage
{
private:
vector<Product> p;
public:
storage(void);
void addProduct(string name,string time,double price,string kind);
};
storage.cpp
#include "storage.h"
#include "Product.h"
storage::storage(void)
{
}
void storage::addProduct(string name,string time,double price,string kind)
{
Product a(time,name,price,kind);
p.push_back(a);
}
菜鸟问题 请耐心解答下 谢谢哈
我是有个Product类,我想在storage类中动态添加Product类的对象,所以用了vector然后就各种错误 ,请大神帮看看,先奉上代码
Product.h
#include <iostream>
using namespace std;
class Product
{
public:
string time1;
string name;
double price;
string kind;
public:
Product(string time,string name,double price,string kind);
string getTime();
string getName();
double getPrice();
string getKind();
};
Product.cpp
#include "Product.h"
Product::Product(string Time1,string Name,double Price,string Kind)
{
time1=Time1;
name=Name;
price=Price;
kind=Kind;
}
string Product::getTime()
{
return time1;
}
string Product::getName()
{
return name;
}
double Product::getPrice()
{
return price;
}
string Product::getKind()
{
return kind;
}
storage.h
#include <iostream>
#include "Product.h"
#include<vector>
using namespace std;
class storage
{
private:
vector<Product> p;
public:
storage(void);
void addProduct(string name,string time,double price,string kind);
};
storage.cpp
#include "storage.h"
#include "Product.h"
storage::storage(void)
{
}
void storage::addProduct(string name,string time,double price,string kind)
{
Product a(time,name,price,kind);
p.push_back(a);
}
菜鸟问题 请耐心解答下 谢谢哈
作者: fireylee 发布时间: 2011-12-04
public:
string time1;
string name;
double price;
string kind;
第一个错误,你这都是公有的,你都直接可以通过点操作来获取数据了,你还设计函数来获取数据,改为私有
#include "storage.h"
#include "Product.h"
storage::storage(void)
{
}
void storage::addProduct(string name,string time,double price,string kind)
{
Product a(time,name,price,kind);
p.push_back(a);
}
这里头文件重复包含了,你应该用
#ifndef ...
#define ...
//头文件。。。
#endif
要用这种格式把头文件处理一下
string time1;
string name;
double price;
string kind;
第一个错误,你这都是公有的,你都直接可以通过点操作来获取数据了,你还设计函数来获取数据,改为私有
#include "storage.h"
#include "Product.h"
storage::storage(void)
{
}
void storage::addProduct(string name,string time,double price,string kind)
{
Product a(time,name,price,kind);
p.push_back(a);
}
这里头文件重复包含了,你应该用
#ifndef ...
#define ...
//头文件。。。
#endif
要用这种格式把头文件处理一下
作者: qscool1987 发布时间: 2011-12-04
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28