initializing argument 1 of `...
I've come across an error that i can't even begin to understand.
I have a function that turns text into a class (file2Agent()). It calls a function that reads formatted text in a file (read(ifstream)). I have no idea what's wrong.
here's the code for file2Agent:
Code:
agent *fileManager::file2Agent()
{
cerr<<"mark 3";
agent *phead= 0;
cin.get();
ifstream fin("agents.DATA");
if(!fin) //did we get the file open?
{
cerr<<endl<<endl<<"\aCouldn't open file in agent *fileManager::file2Agent()"; //nope
return phead;
}//if
vector <agent*> parray;
while (1) //get an agent
{
phead = read(fin); //compiler complains about this line
if (phead != 0);
{
parray.push_back(phead); //put it into a vector
continue;
}//if
break;
}//while
cin.get();
fin.close();
vector2Agent(parray,phead);
cerr<<endl<<endl;
phead->display(); //testing
return phead;
}//file2Agent
here's the code for read:
Code:
agent* fileManager::read(ifstream fin)
{
agent *phead = 0;
char ch;
int id;
string s1,s2,s3;
while (fin.get(ch)) //read a character
{
if (ch = 'a') //is it the begining of an agent
{
fin.get(ch); //eat up newline
id = getNum(fin);//if making additions or subtractions to agent class; mod these---
s1 = getString(fin); // |
s2 = getString(fin);// |
s3 = getString(fin);// |
phead = new agent(id,s1,s2,s3,0);// ---
return phead;
}//if
}//while
return phead; //no agent found
}//read()
here's the error:
Quote:
In file included from archivermain.cpp
In copy constructor `std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)':
`std::ios_base::ios_base(const std::ios_base&)' is private
within this context
In copy constructor `std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)':
`std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]' is private
within this context
In member function `agent* fileManager::file2Agent()':
initializing argument 1 of `agent* fileManager::read(std::ifstream)'
Thank you
Why isn't this obvious to me...
I now have a problem with an operator=. I think the answer should be obvious but I'm not seeing it.
Here's the operator=(it's in my agent class):
Code:
agent agent::operator=(agent &agentFull)
{
this->setClientName(agentFull.getClientName()) ;
this->setIdNum(agentFull.getIdNum());
this->setFileType(agentFull.getFileType());
this->setPath(agentFull.getPath());
this->setNextAgent(0);
return *this;
}
(side note: What does rhs stand for and why do people use it?)
I run into a problem when I try to use it with my file2Agent function. It gives me this error:
Code:
no match for 'operator=' in 'temp = fileManager::file2Agent()()'
note candidates are: agent agent::operator=(agent&)
here's where I call it:
Code:
agent temp;
cerr<<"mark 1";
temp = GLOBALfile.file2Agent(); //GLOBALfile is an instance of my fileManager class. I've forgotten why it's global now
here's the file2Agent() (it returns a single agent by value):
Code:
agent fileManager::file2Agent()
{
cerr<<"mark 3";
agent empty;
agent *phead = 0;
empty.setIdNum(-1);
cin.get();
ifstream fin("agents.DATA");
if(!fin) //did we get the file open?
{
cerr<<endl<<endl<<"\aCouldn't open file in agent *fileManager::file2Agent()"; //nope
return empty;
}//if
vector <agent> parray;
while (fin >> empty) //get an agent
{
parray.push_back(empty); //put it into a vector
}//if
cin.get();
fin.close();
cerr<<"in";
vector2Agent(parray,phead);
cerr<<"out";
empty = *phead;
return empty;
}//file2Agent
Will I run into problems with the agents in the list after the agent I pass by value due to pointer/scope problems? Is it possible to template an overloaded operator?