<分区>
这是我第一次使用 C++ 处理类。我想知道是否有人可以帮助我为以下类正确设计复制构造函数和赋值运算符。
下面的帖子讲的是三分法则,
虽然,我的代码如何实现它并不是很清楚。
信息.h
#ifndef INFO_H
#define INFO_H
class INFO{
public:
std::string label, type;
unsigned int num;
double x, y, z, velx, vely, velz;
void print(std::ostream& stream);
void mod_print(std::ostream& stream);
void read(std::istream& stream);
void mod_read(std::istream& stream);
double distance(INFO *i,double L);
INFO(std::istream& stream);
INFO(){};
};
#endif
信息.cpp
#include "INFO.h"
void INFO::print(std::ostream& stream)
{
stream << label <<'\t'<< type <<'\t'<< num <<'\t'<< x<<'\t'<<y<<'\t'<< z << '\n';
}
void INFO::mod_print(std::ostream& stream)
{
stream << label <<'\t'<< type <<'\t'<< x<<'\t'<<y<<'\t'<< z << '\n';
}
void INFO::read(std::istream& stream)
{
stream >> label >> type >> num >> x >> y >> z;
}
void INFO::mod_read(std::istream& stream)
{
stream >> label >> type >> x >> y >> z;
}
double INFO::distance(INFO *i,double L)
{
double delx = i->x - x - std::floor((i->x-x)/L + 0.5)*L;
double dely = i->y - y - std::floor((i->y-y)/L + 0.5)*L;
double delz = i->z - z - std::floor((i->z-z)/L + 0.5)*L;
return delx*delx + dely*dely + delz*delz;
}
INFO::INFO(std::istream& stream)
{
stream >> label >> type >> num >> x >> y >> z;
}