第一个向量,优胜者向量,抛出未解决的外部错误符号错误,我似乎无法确定问题所在。WinnerVector是一个包含Winner类对象的向量。当使用整数实现相同的代码时,不会发生任何问题。
这两个错误如下:“错误1错误LNK2019:无法解析的外部符号“ public:__thiscall Winner :: Winner(class std :: basic_string,class std :: allocator>)”(0Winner @@ QAE @ V?$在函数_wmain C:\ Users \ cjbernier \ Documents \ Classes UML \ UML FALL 2014 \ Computing III中引用的basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ Z) (92.201.202)\ HW6_Templates_STL \ STLtester \ STLtester.obj STLtester“
和
“错误2错误LNK1120:1个未解决的外部文件C:\ Users \ cjbernier \ Documents \ Classes UML \ UML FALL 2014 \ Computing III(92.201.202)\ HW6_Templates_STL \ STLtester \ Debug \ STLtester.exe 1 1 STLtester”
// 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;
}
我看到以下问题:
Winner::Winner(std::string)
。这说明了链接器错误。实际上,我看不到任何成员函数的定义Winner
。_Pop_back_n()
啊 这不是std::vector
我所知道的一部分。它是特定于平台的扩展吗?本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句