64,692
社区成员
发帖
与我相关
我的任务
分享
char& CMyString::GetAt( int nIndex )const
{
if (nIndex <= 0 || nIndex > m_nStrLen)
{
return -1; //这里我要返回-1 代表错误,可是定义的函数返回值为cha&
//强转-1也不行,求教有啥好办法 }
return m_lpMyString[nIndex + 1];
}}
class IndexOutOfBoundsException {}
char& CMyString::GetAt( int nIndex )const
{
if (nIndex <= 0 || nIndex > m_nStrLen)
throw IndexOutOfBoundsException();
return m_lpMyString[nIndex + 1];
}