1
1>Main.obj : error LNK2019: unresolved external symbol "void __cdecl createVideoList(class                          std::basic_ifstream<char,struct std::char_traits<char> > &,class Video &)" (?createVideoList@@YAXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@AAVVideo@@@Z) referenced in function _main
1>c:\users\******\documents\visual studio 2010\Projects\Programming Assignment 4\Debug\Programming Assignment 4.exe : fatal error LNK1120: 1 unresolved externals

我正在处理编程作业,并且在尝试编译时收到此链接错误 2019。它引用了 createVideoList,这些是与此相关的代码行:

#include <iostream>
#include <fstream>
#include <string>
#include "Video.h"
using namespace std;

void createVideoList(ifstream& infile, Video videoArray);

int main()
{
...
createVideoList(inputfile, videoArray[50]);
}

void createVideoList(ifstream& ifile, Video videoArray[50])
{
string title;
string star1;
string star2;
string producer;
string director;
string productionCo;
int inStock;
int count = 0;
Video newVideo;
getline(ifile, title);
while (ifile)
{
    getline(ifile, star1);
    getline(ifile, star2);
    getline(ifile, producer);
    getline(ifile, director);
    getline(ifile, productionCo);
    ifile >> inStock;
    newVideo.setVideoInfo(title, star1, star2, producer,
        director, productionCo, inStock);
    videoArray[count] = newVideo;
    getline(ifile, title);
}
}

不确定我需要在这里发布什么代码来帮助你们,因为我什至不确定错误在说什么。提前致谢!

4

1 回答 1

5
void createVideoList(ifstream& infile, Video& videoArray);

它应该是

void createVideoList(ifstream& infile, Video* videoArray);

这两个是不同的声明。在第一个中,第二个参数是对 Video 变量的引用,第二个是指针,它可能是一个数组,在你的情况下是什么。

此外,如果您想将数组作为参数传递给函数,您应该这样调用它:

createVideoList(inputfile, videoArray[]);

或者

createVideoList(inputfile, videoArray);

因为当你这样做时:

createVideoList(inputfile, videoArray[50]);

你只是传递数组的第 50 个元素。

于 2012-07-02T19:11:28.137 回答