Hey guys,
I'm trying to work through an exercise dealing with class templates but i'm receiving this error:
error LNK2019: unresolved external symbol "public: class std::valarray<int> & __thiscall Pair<class std::valarray<int>,class std::valarray<int> >::second(void)" (?second@?$Pair@V?$valarray@H@std@@V12@@@QAEAAV?$valarray@H@std@@XZ) referenced in function "public: void __thiscall Wine::GetBottles(void)" (?GetBottles@Wine@@QAEXXZ) C:\Users\CP\Documents\Visual Studio 2010\Projects\CH14 Q1\Wine.obj CH14 Q1
It seems to me it has a problem with one of my calls to a function in my template class called Pair. I am pretty sure I have included all the appropriate header files. I included valarray and Pair.h. I am pretty stumped as to why its not linking. Here is the code:
void Wine::GetBottles()
{
if (Years < 1)
std::cout << "\nNo years to enter data for or invalid number!";
else
{
std::cout << "Enter " << Name << " data for " << Years << " year(s): " << std::endl;
for (int i = 0; i < Years; i++)
{
std::cout << "Enter year: ";
(std::cin >> YearBot.first()[i]).get();
std::cout << "Enter bottles for that year: ";
(std::cin >> YearBot.second()[i]).get();
}
}
}
If you would like more information here is the Wine.h file:
#ifndef WINE_H
#define WINE_H
#include <iostream>
#include <string>
#include <valarray>
#include "Pair.h"
typedef std::valarray<int> ArrayInt;
typedef Pair<ArrayInt, ArrayInt> PairArray;
class Wine
{
private:
std::string Name;
int Years;
PairArray YearBot;
public:
Wine();
Wine(constchar * l, int y, constint yr[], constint bot[]);
Wine(constchar * l, int y);
void GetBottles(); //Asks for bottle and year input
void Show() const; //Displays current object
const std::string & Label() {return Name;} //Displays the label for the object
int Sum(); //Returns total number of bottles for the object
};
#endif