我正在尝试为Array类重载运算符<< >>!= == =和[].应用程序在运行时崩溃,但没有显示编译错误.什么可能是错的?IDE使用了dev c ++
这是array.h
#ifndef ARRAY_H
#define ARRAY_H
#include <iostream>
using namespace std;
class Array{
friend ostream & operator << ( ostream &, const Array & );
friend istream & operator >> ( istream &, Array &);
private:
int size;
int * ptr;
public:
Array ( int = 10 );
Array ( const Array & ); //copy constructor
~Array ();
const Array &operator=( const Array & );
bool operator == ( const Array & ) const;
bool …Run Code Online (Sandbox Code Playgroud) 我收到一个编译错误,说“左”和“右”不明确。
我是否在错误的地方宣布左,右?
我该如何解决?
最小测试用例:
#include <iostream>
using namespace std;
int left = 0, right = 0;
int main()
{
cout << left;
cout << right;
}
Run Code Online (Sandbox Code Playgroud)
正在给:
prog.cpp: In function ‘int main()’:
prog.cpp:6:13: error: reference to ‘left’ is ambiguous
prog.cpp:3:5: error: candidates are: int left
In file included from /usr/include/c++/4.7/ios:43:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from prog.cpp:1:
/usr/include/c++/4.7/bits/ios_base.h:918:3: error:
std::ios_base& std::left(std::ios_base&)
prog.cpp:7:13: error: reference to ‘right’ is ambiguous
prog.cpp:3:15: error: candidates are: int right
In file included from /usr/include/c++/4.7/ios:43:0, …Run Code Online (Sandbox Code Playgroud)