English 中文(简体)
定义 经营者
原标题:Defining >> operator
  • 时间:2011-08-13 20:10:36
  •  标签:
  • c++

我不能执行,不执行;

ostream&operator>>(Mode&refMode,ostream&os)

作为链条运行

refMode.iMode>>(refMode.jMode>>os)

请让我介绍一下它的执行情况?

最佳回答

页: 1 Oli在其评论中说,我们normally界定了operator << for streaming。 你们不要改变经营者通常的犹豫不决。 尽管如此,我并没有看到你的想法遇到任何其他技术障碍。 例:

#include <iostream>
class A
{
   int i;
public:
   A(int i = 0):i(i){}
};

std::ostream& operator>>(const A& a, std::ostream& os)
{
    return os << a.i;
}

int main()
{
   A a(4), b(3);
   a >> (b >> std::cout);
}

但是,为什么你们想要这样做呢?

问题回答

我很抱歉,但运营商和经营商都gt;以及“设计”和“设计”;他们都是联系经营人。 你可以做一些事情,例如:obj1 >> obj2 >> obj3 >>> 溪流,并期望它适当开展工作。 在最好的情况下,你需要大量的括号:obj1 >> (obj2 >> (obj3 >> stream)

仅与常规合成物:

std::ostream& operator << (std::ostream& stream, const MyObject& obj)
{
    stream << obj.variable1 << obj.variable2 << etc etc;
    return stream;
}

可通过这一途径:<条码>流带;< obj1 << obj2 << obj3。

在其他地方,你给我们尝试:

ostream&operator >> (const SomeClass& refToCls, stream&os)
{
   refToCls.iVar>>os;
   return os;
}

我告诉你,你仍然需要传统的yn子inside,因为你没有把你后面的yn子放在任何<条码>上。 页: 1

ostream&operator >> (const SomeClass& refToCls, ostream& os)
{
   os << refToCls.iVar;
   return os;
}

SomeClass x;
x >> cout;

而最后一点警告,这确实是一个坏的思想:





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签