2014-11-08 86 views
-1

第一个向量,优胜者向量抛出未解析的外部错误符号错误,我似乎无法确定问题。 winnerVector是一个包含Winner类对象的向量。当使用整数实现相同的代码时,不会出现问题。向量类类型导致无法解析的外部符号错误LNK2019

这两个错误如下: “Error 1 error LNK2019:unresolved external symbol”public:__thiscall Winner :: Winner(class std :: basic_string,class std :: allocator>)“(?? 0Winner @@ QAE @ V $ $ basic_string @ DU $ char_traits @ D @ std @@ V $ $ allocator @ D @ 2 @@ std @@@ Z)在函数_wmain中引用C:\ Users \ cjbernier \ Documents \ Classes UML \ UML FALL 2014 \计算III(92.201.202)\ HW6_Templates_STL \ STLtester \ STLtester.obj STLtester “

AND

” 错误2错误LNK1120:1周无法解析的外部C:\用户\ cjbernier \文件\类UML \ UML FALL 2014 \ Computing III(92.201.202)\ HW6_Templates_STL \ STLtester \ Debug \ STLtester.exe 1 1 STLt酯”

// STLtester.cpp : Defines the entry point for the console application. 
// This program demostrates 5 different STL containers and uses several 

#include "stdafx.h" 
#include <algorithm> 
#include <iostream> 
#include <vector> 
#include <list> 
#include <stack> 
#include <set> 
#include <iomanip> 
#include <string> 
#include <map> 

using namespace std; 

#pragma once 
class Winner { 
public: 
    Winner(string name = " "); 
    void setName(string name); 
    const string& getName(); 
    friend ostream &operator << (ostream &output, const Winner &x); 

private: 
    string fullName; 
}; 

ostream &operator << (ostream &output, const Winner &x) { 
    output << endl << x.fullName; 
    return output; 
} 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
     // demonstrating vector template class 
     cout << "creating an object of the vector class\n"; 
     vector<Winner> winnerVector; 

     winnerVector.push_back(Winner("George Smith")); 

     cout << "the vector contains the following values:\n"; 
     vector<Winner>::iterator n; 
     for (n = winnerVector.begin(); n != winnerVector.end(); n++) 
     cout << *n << " "; 

     cout << "\n\nadding an element to the vector:\n"; 
     winnerVector.push_back(Winner("Ron Howard")); 

     cout << "the vector now contains the following values:\n"; 

     for (n = winnerVector.begin(); n != winnerVector.end(); n++) 
     cout << *n << " "; 

     cout << "\n\nremoving the last element of the vector:\n"; 
     winnerVector.pop_back(); 

     cout << "the vector now contains the following values:\n"; 

     for (n = winnerVector.begin(); n != winnerVector.end(); n++) 
     cout << *n << " ";  

    // Demonstrating Vector Template Class 
    cout << "Creating an object of the vector class\n"; 
    vector<int> intVector; 

    cout << "Populating the vector with the integers 0-9\n"; 
    for (int i = 0; i <= 9; i++) { 
     intVector.push_back(i); 
    } 

    cout << "The vector contains the following values:\n"; 
    vector<int>::iterator j; 
    for (j = intVector.begin(); j != intVector.end(); j++) 
     cout << *j << " "; 

    cout << "\n\nAdding an element to the vector:\n"; 
    intVector.push_back(10); 

    cout << "The vector now contains the following values:\n"; 

    for (j = intVector.begin(); j != intVector.end(); j++) 
     cout << *j << " "; 

    cout << "\n\nRemoving the last 3 elements of the vector:\n"; 
    intVector._Pop_back_n(3); 

    cout << "The vector now contains the following values:\n"; 

    for (j = intVector.begin(); j != intVector.end(); j++) 
     cout << *j << " "; 

    // Demonstrating the List Template Class 
    cout << "\n\nCreating an object of the list class\n"; 
    list<char> charList; 
    cout << "Populating the list with the letters of the alphabet\n"; 
    for (char letter = 'A'; letter <= 'Z'; letter++) { 
     charList.push_back(letter); 
    } 

    cout << "The list contains the following values:\n"; 
    list<char>::iterator k; 
    for (k = charList.begin(); k != charList.end(); k++) 
     cout << *k << " "; 

    cout << "\n\nThe alphabet backwards is:\n"; 
    list<char>::reverse_iterator rev; 
    for (rev = charList.rbegin(); rev != charList.rend(); rev++) 
     cout << *rev << " "; 

    cout << "\n\nClearing the list:\n"; 
    charList.clear(); 
    cout << "The list size is now: " << charList.size(); 

    // Demonstrating Stack Template Class 
    cout << "\n\nCreating an object of the stack class\n"; 
    stack<double> doubleStack; 

    cout << "Enter a series of double numbers and press enter.\n"; 
    double nextDouble; 
    char nextChar; 
    cin.get(nextChar); 

    while (nextChar != '\n') 
    { 
     cin.putback(nextChar); 
     cin >> nextDouble; 
     doubleStack.push(nextDouble); 
     cin.get(nextChar); 
    } 

    cout << "\nThe double values in reverse order are: \n"; 
    while (!doubleStack.empty()) 
    { 
     cout << showpoint << setprecision(2) << doubleStack.top() << " "; 
     doubleStack.pop(); 
    } 

    // Demonstrating Set Template Class 
    cout << "\n\nCreating an object of the set class\n"; 
    set<string> stringSet; 

    stringSet.insert("George Bush"); 
    stringSet.insert("George Bush"); 
    stringSet.insert("Fred Johnson"); 
    stringSet.insert("Chris Lip"); 

    cout << "The set contains the following Winners:\n"; 
    set<string>::const_iterator l; 
    for (l = stringSet.begin(); l != stringSet.end(); l++) 
     cout << " " << *l << endl; 

    cout << "\nSearching for and removing the winner \"Bob Jones\".\n"; 
    stringSet.erase(stringSet.find("Bob Jones")); 

    for (l = stringSet.begin(); l != stringSet.end(); l++) 
     cout << " " << *l << endl; 


    // Demonstrating the map class 
    cout << "\nCreating an object of the map class\n"; 
    map<string, string> cars; 
    map<string, string>::const_iterator m; 

    cout << "Initializing the map:\n"; 
    cars["Ford"] = "Mustang"; 
    cars["Honda"] = "Accord"; 
    cars["Lincoln"] = "MKZ"; 
    cars["Toyota"] = "Corolla"; 
    cars["Dodge"] = "Dakota"; 

    if (cars.empty()) { 
     cout << "The map is empty.\n"; 
    } 
    else { 
     cout << "The list of cars in the map are:\n"; 
     for (m = cars.begin(); m != cars.end(); m++) 
      cout << m->first << " - " << m->second << endl; 
    } 

    cout << "\nThe vehicle for Ford is: " << cars["Ford"] << endl << endl; 

    if (cars.find("Nissan") == cars.end()) 
     cout << "Nissan is not in the map."; 

    cout << "\n\nThere are vehicles in the map: " << cars.size(); 

    cout << "\n\nPress any key to exit."; 
    cin.get(); 
    return 0; 
} 
+0

显示整个错误信息 – 2014-11-08 05:57:29

+0

请从头开始粘贴错误的完整列表... – ravi 2014-11-08 05:58:49

回答

1

我看到了以下问题:

  1. 没有的Winner::Winner(std::string)定义。这解释了链接器错误。实际上,我没有看到Winner的任何成员函数的定义。
  2. 什么是_Pop_back_n()?这不是我所知道的std::vector的一部分。这是一个特定于平台的扩展吗?
+0

啊,是的,谢谢!我的错。 – 2014-11-08 18:29:26

相关问题