English 中文(简体)
装载超重的经营者< 返回
原标题:Overloaded operator<< returning ostream&

在样本应用中,我有以下代码:

ostream& operator<< (ostream& os, const ReferenceTest& rt)
{
    os << rt.counter;  //In this scenario, rt has a public int called counter
}

我很惊讶地获悉,该法典没有使用海合会4.6.1编成册。 由于我本期望的原因,即在使用“2010年视觉演播室”时,它失败了,即Im没有回过提及stream。 然而,为这两个平台汇编的方案产出是一样的(我拥有书写测试产出的三维主)。

Which is standards compliant? Am I missing something obvious here?

- Derek

最佳回答

你们能否用警告汇编? 我收到<条码>警报:控制达到无功能和g++。

你当然不想让汇编者在你的法典中留下第一个错误。 你们希望它能够赶上一个well光灯。 为此,汇编者必须分发贵方法典,以便其能够发挥作用。 在该案中,分机是显而易见的:回归是作为论据提供的。

从来没有相信由汇编者免费提供的“固定”。 这些只是免费的。 而代之,你们的法典。

总是能够编制警报。

问题回答

除返回声明外,还缺少其他东西? 缺乏这一规定是不明确的行为(我甚至会期望它会成为这种简单案例的汇编时间错误)。 可能发生的情况是,从<代码>os << rt.counter的回归数值出现在整个<代码>operator<<的回报值预计到同一地点,从而使其得以偶然工作。





相关问题
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?

热门标签