为什么在c或c ++中不支持添加两个指针.
当我做,
int *ptr,*ptr1;
int sum = ptr + ptr1;
Run Code Online (Sandbox Code Playgroud)
C或C++会抛出错误.虽然它支持,
int diff = ptr - ptr1;
Run Code Online (Sandbox Code Playgroud) 我的代码非常类似于此:
LINT_rep::Iterator::difference_type LINT_rep::Iterator::operator+(const Iterator& right)const
{
return (this + &right);//IN THIS PLACE I'M GETTING AN ERROR
}
LINT_rep::Iterator::difference_type LINT_rep::Iterator::operator-(const Iterator& right)const
{//substracts one iterator from another
return (this - &right);//HERE EVERYTHING IS FINE
}
err msg: Error 1 error C2110: '+' : cannot add two pointers
Run Code Online (Sandbox Code Playgroud)
为什么我只在一个地方而不是两个地方都收到错误?