Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译时出现此错误:错误LNK2019:我在main中为两个定义的函数获取它们_C++_Visual Studio 2010 - Fatal编程技术网

C++ 编译时出现此错误:错误LNK2019:我在main中为两个定义的函数获取它们

C++ 编译时出现此错误:错误LNK2019:我在main中为两个定义的函数获取它们,c++,visual-studio-2010,C++,Visual Studio 2010,它主要与两个功能有关。getinput和execfunc。它们是在类Bibliotek中定义的。我找了这个。这可能与远期申报有关吗?错误消息是: 1>------ Rebuild All started: Project: ou4sec, Configuration: Debug Win32 ------ 1> ou4sec.cpp 1> bibliotek.cpp 1> Generating Code... 1>ou4sec.obj : error LNK2

它主要与两个功能有关。getinput和execfunc。它们是在类Bibliotek中定义的。我找了这个。这可能与远期申报有关吗?错误消息是:

1>------ Rebuild All started: Project: ou4sec, Configuration: Debug Win32 ------
1>  ou4sec.cpp
1>  bibliotek.cpp
1>  Generating Code...
1>ou4sec.obj : error LNK2019: unresolved external symbol "void __cdecl execfunc(class std::vector<class Lendobj *,class std::allocator<class Lendobj *> > &,char &,int &)" (?execfunc@@YAXAAV?$vector@PAVLendobj@@V?$allocator@PAVLendobj@@@std@@@std) referenced in function _main
1>ou4sec.obj : error LNK2019: unresolved external symbol "char __cdecl getinput(void)" (?getinput@@YADXZ) referenced in function _main
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\users\jonas\documents\visual studio 2010\Projects\ou4sec\Debug\ou4sec.exe : fatal error LNK1120: 3 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
1>----已启动全部重建:项目:ou4sec,配置:调试Win32------
1> ou4sec.cpp
1> 图书馆
1> 正在生成代码。。。
1> ou4sec.obj:错误LNK2019:未解析的外部符号“void\uu cdecl execfunc(类std::vector&,char&,int&)”(?execfunc@@YAXAAV$vector@PAVLendobj@@V$allocator@PAVLendobj@@@std@@@std)在函数\u main中引用
1> ou4sec.obj:错误LNK2019:未解析的外部符号“char\uu cdecl getinput(void)”(?getinput@@YADXZ)在函数\u main中引用
1> MSVCRTD.lib(crtexew.obj):错误LNK2019:未解析的外部符号_WinMain@16在函数\uuuu\tMainCartStartup中引用
1> c:\users\jonas\documents\visual studio 2010\Projects\ou4sec\Debug\ou4sec.exe:致命错误LNK1120:3个未解析的外部
=========全部重建:0成功,1失败,0跳过==========
文件(主)ou4sec.cpp:

#include "bok.h"
#include "cd.h"
#include "tidskrift.h"
#include "fack.h"
#include "nonfack.h"
#include "lendobj.h"
#include <iostream>
#include <fstream>
using namespace std;
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>


char getinput();
void execfunc(vector <Lendobj*> &bib,char &c, int &antal);
int main()
{
  char c;
  int antal = 0;
  vector <Lendobj*> biblio;
    fstream inf;
    inf.open("biblio.txt");
    std::string titel;
    std::string forf;
    int id;
    int cnr;
    std::string vol;
    std::string art;
    std::string typ;
    string tid;
     // If we couldn't open the input file stream for reading
    if(inf.is_open())
    {


         while (inf.good())
    {
        // read stuff from the file into a string and print it
        std::string strInput;
        std::string typ;
        int i = 0;
        while(getline(inf, strInput))
            {
        if(strInput == "Fiction")
        {
            typ = strInput;
            getline(inf, strInput);
            forf = strInput;
            getline(inf, strInput);
            titel = strInput;
            getline(inf, strInput);
            id = atoi (strInput.c_str());
            getline(inf, strInput);
            cnr = atoi (strInput.c_str());
            biblio.push_back(new Nonfack(typ,id, titel, cnr, forf));
            i = i +1;
        }
        if(strInput == "NonFiction")
        {
            typ = strInput;
            getline(inf, strInput);
            forf = strInput;
            getline(inf, strInput);
            titel = strInput;
            getline(inf, strInput);
            id = atoi (strInput.c_str());
            getline(inf, strInput);
            cnr = atoi (strInput.c_str());
            biblio.push_back(new Fack(typ,id, titel, cnr, forf));
            i = i +1;
        }
        if(strInput == "Journal")
        {
            typ = strInput;
            getline(inf, strInput);
            titel = strInput;
            getline(inf, strInput);
            vol = strInput;
            getline(inf, strInput);
            id = atoi (strInput.c_str());
            getline(inf, strInput);
            cnr = atoi (strInput.c_str());
            biblio.push_back(new Tidskrift(typ,id, titel, cnr, vol));
            i = i +1;
        }
        if(strInput == "CD")
        {
            typ = strInput;
            getline(inf, strInput);
            art = strInput;
            getline(inf, strInput);
            titel = strInput;
            getline(inf, strInput);
            tid = strInput;
            getline(inf, strInput);
            id = atoi (strInput.c_str());
            getline(inf, strInput);
            cnr = atoi (strInput.c_str());
            biblio.push_back(new Cd(typ,id, titel,cnr, art, tid));
            i = i +1;
        }
        }
        antal = i;
        inf.close();
    }

    }
    else cout << "Unable to open file"<<endl; 
  cout << "antal : " << antal << endl;
  cout <<"Choose one of X/C/F/N/J/H(help)/S/B/R/Q: "<< endl;
  while(1)
  {
      c = getinput();
      if(c=='Q')
          break;
      execfunc(biblio, c, antal);
  }
  remove("biblio.txt");
  for(int i = 0;i < antal;i++)
  {
      biblio[i]->quit();
  }
  return 0;
}
#包括“bok.h”
#包括“cd.h”
#包括“tidskrift.h”
#包括“fack.h”
#包括“nonback.h”
#包括“lendobj.h”
#包括
#包括
使用名称空间std;
#包括
#包括
#包括
#包括
char getinput();
void execfunc(矢量和bib、字符和c、内部和内部);
int main()
{
字符c;
int antal=0;
矢量图书馆;
fstream-inf;
inf.open(“biblio.txt”);
标准:字符串滴度;
std::字符串forf;
int-id;
国际计算机网络;
std::字符串卷;
弦乐艺术;
std::字符串类型;
字符串tid;
//如果我们无法打开输入文件流进行读取
如果(inf.is_open())
{
while(inf.good())
{
//将文件中的内容读入字符串并打印出来
std::字符串strInput;
std::字符串类型;
int i=0;
while(getline(inf,strInput))
{
if(strInput==“虚构”)
{
典型值=strInput;
getline(inf,strInput);
forf=strInput;
getline(inf,strInput);
滴度=strInput;
getline(inf,strInput);
id=atoi(strInput.c_str());
getline(inf,strInput);
cnr=atoi(strInput.c_str());
图书馆推回(新的非备份(类型、id、滴度、cnr、forf));
i=i+1;
}
if(strInput==“非虚构”)
{
典型值=strInput;
getline(inf,strInput);
forf=strInput;
getline(inf,strInput);
滴度=strInput;
getline(inf,strInput);
id=atoi(strInput.c_str());
getline(inf,strInput);
cnr=atoi(strInput.c_str());
图书馆推回(新Fack(类型、id、滴度、cnr、forf));
i=i+1;
}
如果(strInput==“日记账”)
{
典型值=strInput;
getline(inf,strInput);
滴度=strInput;
getline(inf,strInput);
vol=strInput;
getline(inf,strInput);
id=atoi(strInput.c_str());
getline(inf,strInput);
cnr=atoi(strInput.c_str());
图书馆推回(新的Tidskrift(类型、id、滴度、cnr、卷));
i=i+1;
}
if(strInput==“CD”)
{
典型值=strInput;
getline(inf,strInput);
艺术=严格;
getline(inf,strInput);
滴度=strInput;
getline(inf,strInput);
tid=strInput;
getline(inf,strInput);
id=atoi(strInput.c_str());
getline(inf,strInput);
cnr=atoi(strInput.c_str());
图书推送(新Cd(类型、id、滴度、cnr、艺术、tid));
i=i+1;
}
}
antal=i;
inf.close();
}
}

else cout问题在于您的
main
forward声明了这两个函数

char getinput();
void execfunc(vector <Lendobj*> &bib,char &c, int &antal);

如果要调用
Bibliotek
的成员函数,如果函数是非静态的(即需要引用非静态成员变量),则需要使用成员语法调用它们,或者使用
Bibliotek::getinput()
如果对应的函数是静态的。在这两种情况下,您都需要删除插入到
main
中的函数的正向声明,并将其替换为包含声明
Bibliotek
类的标头。

您的函数在类
Bibliotek
中定义。因此,您需要我们称之为合格:

c = Bibilotek::getinput();


并从
main.cpp
中删除多余的全局函数声明,因为您可能不需要这些声明。

在bibliotek.cpp文件中有一个实现。如下所示:为什么它不能与前向声明一起工作?我是该语言的新手。@user2224247前向声明承诺提供定义。您不支持查看这些函数的定义,这就是链接器抱怨的原因。您提供的是成员函数的定义,而不是普通函数。您需要使用
Bibliotek::
前缀调用它们,并声明它们
static
。您已经解决了!谢谢。但我仍然有一条错误消息。它是否与include files一起使用:1>----重建所有started:Project:ou4sec,配置:Debug Win32-----1>ou4sec.cpp 1>bibliotek.cpp 1>生成代码…1>msvcrdt.lib(crtexew.obj):错误LNK2019:未解析的外部符号_WinMain@16在函数\uuuuu tmainCRTStartup 1>c:\users\jonas\documents\visual studio 2010\Projects\ou4sec\Debug\ou4sec.exe中引用:致命错误LNK1120:1未解析的外部=======================全部重建:0成功,1失败,0跳过=====我尝试了我的项目的另一个版本,它编译得很好现在,非常感谢!可能是
char getinput();
void execfunc(vector <Lendobj*> &bib,char &c, int &antal);
char Bibliotek::getinput();
void Bibliotek::insert(vector <Lendobj*> &bib,char &type, int &antal);
c = Bibilotek::getinput();
Bibliotek::execfunc(biblio, c, antal);