小编Aas*_*bab的帖子

无法重载运算符,因为无法访问类中声明的私有成员

我有一个运算符重载的类,如下所示:

friend ostream operator<< (ostream &stream, const Item &item){
          stream << item.title << " - " << item.format << " (Loaned to " << item.name << ") on " << item.date;
          return stream;
    }
Run Code Online (Sandbox Code Playgroud)

我的程序无法编译,并给我以下错误:

error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 8\vc\include\ios(151) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1> …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio

1
推荐指数
1
解决办法
48
查看次数

简单赋值时内存分配错误

为了从给定路径获取父目录,我有以下代码。注:为size_t是一种类型定义为unsigned int类型。

/****************************************************
This function takes a full path to a file, and returns
the directory path by returning the string up to the last backslash.

Author: Aashish Bharadwaj
*****************************************************/
_TCHAR* GetDirectoryFromPath(const _TCHAR* path)
{
   size_t size = _tcslen(path);
   size_t lastBackslash = 0;
   for (size_t i = 0; i < size; i++)
   {
      if (path[i] == '\\')
      {
         lastBackslash = i;
      }
   }

   _TCHAR* dirPath = new _TCHAR();
   size_t i;
   for (i = 0; …
Run Code Online (Sandbox Code Playgroud)

c++ unicode mfc tchar

-5
推荐指数
1
解决办法
106
查看次数

标签 统计

c++ ×2

mfc ×1

tchar ×1

unicode ×1

visual-studio ×1