我有一个运算符重载的类,如下所示:
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) 为了从给定路径获取父目录,我有以下代码。注:为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)