-2

Updated the files and I still get the following errors.

  • 1 Unresolved externals (lab12.exe line 1)
  • unresolved external symbol "public char__thiscall Pair::geetFirst(void)" (?getFirst@?$Pair@D@@QAEDXZ) referenced in function_main (lab12.obj line 1)

Pair.h

#pragma once
template <class T>
class Pair
{

private:
    T theFirst;
    T theSecond;

public:
    /*Pair(const T& dataOne, const T& dataTwo);*/
    Pair(T a, T b) {
        theFirst = a;
        theSecond = b;
    }
    T getFirst();
    T getSecond();

};

Pair.cpp

#include "stdafx.h"
#include "Pair.h"


template<class T>
T Pair<T>::getFirst()
{
    return theFirst;
}

template<class T>
T Pair<T>::getSecond()
{
    return theSecond;
}

Main.cpp

#include "stdafx.h"
#include "Pair.h"
#include <iostream>
using namespace std;

int main()
{
    Pair <char> letters('a', 'd');

    cout << letters.getFirst();


    cout << endl;
    system("Pause");

    return 0;
}
Brandon Turpy
  • 883
  • 1
  • 10
  • 32
  • I would have thought that the constructor of pair would initialize `theFirst=dataOne` and `theSecond=dataTwo` – selbie Nov 21 '15 at 06:14
  • 1
    You have dramatically changed the question. The previous answers were applicable, now that are not. It would have been a better idea to ask another question. – Niall Nov 21 '15 at 07:25
  • I did, and they marked it as a duplicate. So I just changed what I was told to fix the naming error and moved the implementation in the .h file.. other than that everything is the same. I updated the question with the new error since they would not let me ask a new one as it was too close i guess! – Brandon Turpy Nov 21 '15 at 07:28
  • The error is solve by implementing everything in the header file, the duplicate contains some good answers. I think you should revert this question to the original error and accept the answer. – Niall Nov 21 '15 at 07:42

2 Answers2

4

You've been bit by using namespace std;. You have your own pair class, but there's a std::pair in the standard library. The compiler can't decide which one to use, so you get an ambiguous symbol error.

Solution: Don't use using namespace std;! Qualify standard library symbols with std:: instead. It saves a lot of headaches like this.

Community
  • 1
  • 1
Fred Larson
  • 60,987
  • 18
  • 112
  • 174
  • Got it, I believe I fixed it, but I am still getting an error I have never seen. Because it is in the .exe and .obj file I have no idea what the issue is... any advice? – Brandon Turpy Nov 21 '15 at 07:19
0

The namespace std also contains a template class called pair.

You will want to wrap your own pair template in its own namespace or name it to something else so you can call it without an ambiguous symbol error.

Gamenotcore
  • 161
  • 4
  • Got it, I believe I fixed it, but I am still getting an error I have never seen. Because it is in the .exe and .obj file I have no idea what the issue is... any advice? – Brandon Turpy Nov 21 '15 at 07:19