0

我目前有一个项目,我通过一个包含数千个名称的文本文件运行并将它们放入二进制存储树中。遇到此错误的绊脚石:

error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'    c:\program files (x86)\microsoft visual studio 10.0\vc\include\fstream  1116

我希望有人可以帮助我解释根本问题。

提前致谢。

乔希

编辑:

BinaryTreeStorage::BinaryTreeStorage(void) : root(NULL)
{

}

BinaryTreeStorage::~BinaryTreeStorage(void)
{

}

void BinaryTreeStorage::insert(string &input, TreeNode *&root)
{
if(root != NULL)
{
    root -> name = input;
    root -> left = NULL;
    root -> right = NULL;
}

else if (input < root -> name)
{
    insert(input, root -> left);
}
else
{
    insert(input, root -> left);
}   
}

string BinaryTreeStorage:: writeToTree(TreeNode *&root)
{
if(root ->left != NULL)
{
    writeToTree(root ->left);
}
return root->name;
if (root->right != NULL)
{
    writeToTree(root);
}
}

void BinaryTreeStorage::write(ofstream nameOut)
{
cout << "Writing out bst names" << endl;
writeToTree(root);
}

void BinaryTreeStorage::read(ifstream& nameIn)
{
cout<< "Reading in bst" << endl;
string name;

for (int i = 0; i < numberOfNames; i++)
{
    nameIn >> name;
    insert (name, root);
}
}
4

1 回答 1

1

在您的write功能中:您不能复制ofstream. 通过引用传递它。再说一次,您似乎从未在正文中使用函数nameOut参数,所以为什么不完全省略它:

void BinaryTreeStorage::write()
{
    cout << "Writing out bst names" << endl;
    writeToTree(root);
}
于 2012-05-07T12:49:09.950 回答