-1

Having a problem with my overloaded << operator, cygwin is returning 2 errors,

    DeckOfCardsDemo.o:DeckOfCardsDemo.cpp:(.text+0xd3): undefined reference to `samuel::operator<<(std::ostream&, samuel::DeckOfCards const&)'

    DeckOfCardsDemo.o:DeckOfCardsDemo.cpp:(.text+0xd3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `samuel::operator<<(std::ostream&, samuel::DeckOfCards const&)'

this is my function in DeckOfCards.cpp

    std::ostream& operator << (std::ostream& out, DeckOfCards& card) 
    {
       return out << card.value() << " ";
    } 

declaration

    friend ostream& operator << (ostream& out, const DeckOfCards& card);

and my DeckOfCardsDemo.cpp

    #include <iostream>
    #include <cstdlib> 
    #include <ctime> 
    #include "DeckOfCards.h"
    using namespace std;
    using namespace samuel;

    int main(int argc, char* argv[]) {

    if (argc >= 2) {

        int seed = atoi(argv[1]);     
    }
    else {
        int seed = time(NULL);
        srand(seed);
    }
    DeckOfCards* deck = new DeckOfCards(); //creating a deck
    cout << deck->value() << endl; //printing deck 
    cout << *deck << endl;


    return EXIT_SUCCESS;


} 
Riggy
  • 7
  • 1
  • 7
  • Your question is answered in the duplicate specifically in [this answer](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574403#12574403). – πάντα ῥεῖ Sep 10 '16 at 12:00

1 Answers1

1

Pay attantion on type of the second argument

      DeckOfCards& card

and

      DeckOfCards const& card

are different types.

So, check the declaration of operator << (unfortunately we cannot see how it was declared)

VolAnd
  • 6,367
  • 3
  • 25
  • 43
  • my bad, I've declared it as friend ostream& operator << (ostream& out, const DeckOfCards& card); – Riggy Sep 10 '16 at 11:34