错误:没有已知的转换

时间:2013-09-19 02:29:45

标签: c++

所以这就是我现在拥有的,我的教授提供的扫描仪。

#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;
 }

主要课程是给我们的,并且涉及按价值而非参考的电话,我的教授开始工作。

我收到的错误是:

 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)’

所以我不太明白发生了什么。我看到的任何地方都说这个问题可以通过引用而不是值来修复。但是,他提供的代码不包括引用的任何调用,这使我认为它是一个更微妙的错误(或它是如此之大,以至于让我眼花缭乱)。不过,无论如何我改变了它,它给了我这些错误:

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’

任何你可以告诉我的都是一个帮助。

提前致谢!

1 个答案:

答案 0 :(得分:1)

我猜测Scanner不是要复制的。语法:

int Similarity::readData(Scanner inFile){

暗示Scanner将从传入的变量复制到此方法通过Scanner的复制构造函数接收的变量。

扫描仪听起来像处理引擎盖下的iostreams。 iostreams库中的流执行not have copy constructors

我不完全清楚你是如何尝试通过引用传递的,但是你需要将此文件中的签名和相应的.h文件更改为:

int Similarity::readData(Scanner& inFile){

你应该没问题。 readData现在接收对传入文件的引用。这实际上是传入的东西的别名 - 你对它做的任何事情都会反映在传入的对象上。