operator-overloading

    0热度

    2回答

    作为一项技术练习,我尝试创建不同的方法来计算三角形周长。 当给出三条边时 - 任务很简单,但当我们得到两条边和它们之间的角度或一条边和两条边时 - 我们应该应用一些三角函数操作。 为了三种情况之间进行区分,我声明边缘作为小数和角度作为浮子,从而给了系统一提示该方法过载(例如:十进制&浮子&十进制=> 2个边和一个角度)。 这不是最优雅的解决方案,因为数据类型不应该用于传输信息。 另一种选择是再添变

    0热度

    2回答

    我一直在努力解决一些学校问题,并且我在operator>>中关心内存分配,但看到了不同的解决方案,所以我在这里有点困惑。operator>>当编译工作良好,提供良好的输出,但我不明白为什么,这里是代码.. (为什么我糊涂了是下面的代码) class Some { protected: char *name; int price; int an

    1热度

    1回答

    class M33 { public: double m[3][3]; double (*GetM())[3] { return m; } }; // call to JPL cspice f2c generated routine // void mxm_c (const double m1 [3][3], // const dou

    0热度

    1回答

    我已经写了下面的一段代码: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; for (auto i=v.begin(); i!=v.end(); ++i) { os << *i << " "; } os << "}";

    0热度

    1回答

    我正试图创建一个书店程序,用于读取用户输入,直到EOF。为了做到这一点,我超负荷istream >> operator等。 class CSales { public: //constructors friend ostream & operator << (ostream &os, const CSales &x) const; friend istream &

    0热度

    1回答

    我有我不能改变的输入文件,具有略微不同线 Supercar HTT Technologies 10 2 Motorcycle Honda 40 1 ... 我为了中的值读入我的数据重载>>操作符结构,主要内容如下: class Vehicles{ private: string type; //type of vehicle, i.e. car/motorcycle string m

    0热度

    1回答

    我试图重载< <运营商检测操作的溢出,下面是我的代码的部分新Integer类: class NewInteger{ private: int num; public: NewInteger(); NewInteger(int); friend std::ostream &operator <<(std

    -1热度

    1回答

    我在重载操作符中实现朋友函数时遇到问题。我对我需要使用这些功能的理解并不了解。如果任何人都可以给我一些关于如何着手的指导。请提前谢谢你。 说明: This class implements rational number of the type 2/3. class Rational; private data: int n, (fraction numerator) int d (fr

    -1热度

    1回答

    我是不寻找任何人为我做我的编码。然而,当调试修复我的代码时,这个概念正在逃避我。 我知道我期待添加一些包含operator(n)的代码,其中(n)是运算符,但我不确定如何识别什么和在哪里。 试图编译下面,我收到错误: C2678 binary '<': no operator found which takes a left-hand operand of type 'Course' C2678

    0热度

    1回答

    根据该article,赋值操作符可以具有下列形式之一: (1) MyClass& operator=(const MyClass& rhs); (2) MyClass& operator=(MyClass& rhs); (3) MyClass& operator=(MyClass rhs); (4) const MyClass& operator=(const MyClass& rhs);