Reputation: 13
So this is what I currently have, with the Scanner provided by my professor.
#include "Similarity.h"
#include "Scanner.h"
using namespace std;
int Similarity::readData(Scanner inFile){
int similarityInputSize;
vector< vector<int> > containingVector;
bool nextValueFound;
similarityInputSize = inFile.nextInt();
int lineCount = 0;
while(inFile.hasNext()){
containingVector.push_back(vector<int>());
for(int i = 0; i < similarityInputSize; i++){
containingVector[lineCount].push_back(inFile.nextInt());
}
lineCount++;
}
for(int i = 0; i < containingVector.size(); i++){
for(int j = 0; j < similarityInputSize; i++){
cout << containingVector[i][j] << " ";
}
cout << endl;
}
return 0;
}
The Main class is given to us and involves a call by value not by reference, which my professor got to work.
the errors I receive are:
In file included from /usr/include/c++/4.7/ios:43:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from ../../Utilities/Utils.h:17,
from Main.h:11:
/usr/include/c++/4.7/bits/ios_base.h: In copy constructor ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’:
/usr/include/c++/4.7/bits/ios_base.h:788:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
In file included from /usr/include/c++/4.7/ios:45:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from ../../Utilities/Utils.h:17,
from Main.h:11:
/usr/include/c++/4.7/bits/basic_ios.h:64:11: error: within this context
In file included from ../../Utilities/Utils.h:18:0,
from Main.h:11:
/usr/include/c++/4.7/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/include/c++/4.7/fstream:420:11: note: synthesized method ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’ first required here
In file included from /usr/include/c++/4.7/ios:44:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from ../../Utilities/Utils.h:17,
from Main.h:11:
/usr/include/c++/4.7/streambuf: In copy constructor ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’:
/usr/include/c++/4.7/streambuf:800:7: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const __streambuf_type&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_streambuf<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]’ is private
In file included from ../../Utilities/Utils.h:18:0,
from Main.h:11:
/usr/include/c++/4.7/fstream:69:11: error: within this context
/usr/include/c++/4.7/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/include/c++/4.7/fstream:420:11: note: synthesized method ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’ first required here
In file included from Main.h:12:0:
../../Utilities/Scanner.h: In copy constructor ‘Scanner::Scanner(const Scanner&)’:
../../Utilities/Scanner.h:27:7: note: synthesized method ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’ first required here
Main.cpp: In function ‘int main(int, char**)’:
Main.cpp:58:31: note: synthesized method ‘Scanner::Scanner(const Scanner&)’ first required here
In file included from Main.h:14:0:
Similarity.h:23:9: error: initializing argument 1 of ‘int Similarity::readData(Scanner)’
So I don't quite understand what happened. Everywhere I looked said that the issue would be fixed by a call by reference not by value. However, his provided code does not include any call by references, which makes me assume its a more subtle error (or its so big that it's blinding me). Nevertheless, I changed it anyways and it gave me these errors:
Similarity.cpp:12:5: error: prototype for ‘int Similarity::readData(Scanner&)’ does not match any in class ‘Similarity’
Similarity.h:23:9: error: candidate is: int Similarity::readData(Scanner)
Main.cpp: In function ‘int main(int, char**)’:
Main.cpp:58:32: error: no matching function for call to ‘Similarity::readData(Scanner*)’
Main.cpp:58:32: note: candidate is:
In file included from Main.h:14:0:
Similarity.h:23:9: note: int Similarity::readData(Scanner)
Similarity.h:23:9: note: no known conversion for argument 1 from ‘Scanner*’ to ‘Scanner’
Anything you can tell me at all will be a help.
Thanks in advance!
Upvotes: 1
Views: 787
Reputation: 65599
I'm guessing Scanner isn't meant to be copied. The syntax:
int Similarity::readData(Scanner inFile){
implies that Scanner will be copied from the passed in variable to the variable received by this method via Scanner's copy constructor.
Scanner sounds like something that deals with iostreams under the hood. Streams in the iostreams library do not have copy constructors.
I'm not entirely clear how you tried to pass by reference, but you need to change the signature in this file and the corresponding .h file to:
int Similarity::readData(Scanner& inFile){
And you should have no problem. readData
now receives a reference to the passed in file. This is essentially an alias of the thing passed in -- anything you do to it will be reflected on the object that was passed in.
Upvotes: 1