gpt4 book ai didi

c++ - 错误 : no known conversion for

转载 作者:太空宇宙 更新时间:2023-11-04 11:49:38 25 4
gpt4 key购买 nike

这就是我目前拥有的,以及我的教授提供的扫描仪。

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

Main 类提供给我们,涉及按值调用而不是按引用调用,这是我的教授开始工作的。

我收到的错误是:

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

所以不太明白是怎么回事。我到处都说这个问题将通过引用而不是值(value)来解决。但是,他提供的代码不包含任何引用调用,这让我认为这是一个更微妙的错误(或者大到让我眼花缭乱)。尽管如此,我还是改变了它,它给了我这些错误:

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’

任何你能告诉我的都会对我有帮助。

提前致谢!

最佳答案

我猜 Scanner 不是用来复制的。语法:

int Similarity::readData(Scanner inFile){

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

Scanner 听起来像是在底层处理 iostreams 的东西。 iostreams 库中的流执行 not have copy constructors .

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

int Similarity::readData(Scanner& inFile){

你应该没有问题。 readData 现在收到对传入文件的引用。这本质上是传入事物的别名——您对其所做的任何操作都会反射(reflect)在传入的对象上。

关于c++ - 错误 : no known conversion for,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18885344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com