3

I have tried to google this error and have not found anything useful. Im pretty new at programming so please bear with me. This error showed when I first compiled card.cpp and has not gone away since then. All of my cpp files for this program are giving the same error. When I compile I keep getting this when I type in g++ card.cpp (or any of my .cpp files)-

/tmp/ccW6ByXY.s: Assembler messages:
/tmp/ccW6ByXY.s:13: Error: symbol `_ZNSi6ignoreE' is already defined
/tmp/ccW6ByXY.s:25: Error: symbol `_ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreE' is already defined

I have my driver and 3 .h files (with their respective .cpp files). When I compile each one separately or together they each give this message. Any information is appreciated.

#include "card.h"
//using namespace std;


Card::Card()
{
    rank = 'A';
    suit = spades;
}

Card::Card(int _rank, Suit _suit)
{
    rank = _rank;
    suit = _suit;
}

string Card::toString() const //return string of card (ie 2h)
{
    string cardString = suitString() + rankString();
    return cardString;
}

int Card::getRank() const
{
    return rank;
}

Card::Suit Card::getSuit() const
{
    return suit;
}

bool Card::operator == (const Card &rhs) const
{
    return (rank==rhs.rank) || (suit == rhs.suit);
}

string Card::suitString() const
{
    Suit s = spades;
    switch(s)
    {
        case spades: return "s";
            break;
        case hearts: return "h";
            break;
        case diamonds: return "d";
            break;
        case clubs: return "c";
            break;
    }
}

card.h is below

#ifndef _CARD_H
#define _CARD_H


#include <iostream>
#include <string>
using namespace std;

class Card
{
public:

    enum Suit {spades, hearts, diamonds, clubs};

    Card();                     // default: ace of spades

    Card(int, Suit);

    string toString()   const;  // return string version: Ac 4h Js
    int   getRank()     const;  // return rank, 1..13
    Suit  getSuit()     const;  // return suit


    bool operator == (const Card &rhs) const;

private:

    int rank;
    Suit suit;

    string suitString()  const;  // return "s", "h",...
    string rankString()  const;  // return "A", "2", ..."Q"

};

#endif
Ana
  • 31
  • 2
  • 1
    Please add your build command. – Pradhan Feb 11 '15 at 05:12
  • I've formatted your code (A-style) for you, so that myself & others, may find it more legible than before. Also note that names beginning with an underscore, is reserved for the implementation.. See: http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier – Brandon Feb 11 '15 at 05:33
  • I don't see anything wrong with the source. So, card.h please. – Pradhan Feb 11 '15 at 05:36
  • Feel free to use ideone.com or coliru.stacked-crooked.com if you feel that there are too many files to add here. – Pradhan Feb 11 '15 at 05:37
  • In addition to the leading underscore names being reserved, you are missing the implementation for `string Card::rankString() const` so your code cannot be compiled. You are also missing the default case or default return value for `suitString`. It's bad practice to do `using namespace std` in headers. Adding these, I was able to compile your code without error. The error you are seeing must stem from somewhere else. – Brandon Feb 11 '15 at 05:51
  • @Brandon I have the other functions written it was just how much I was allowed to copy and paste. It wouldn't let me scroll down to copy more. The other functions came after the error started appearing as well which is why I didn't rush to go back and do a second copy/paste. Thank you for trying to help :) – Ana Feb 11 '15 at 05:57
  • Oh okay. Are you using `cin.ignore`, `wcin.ignore`, `stringstream.ignore`, anything at all that has "ignore" in it? Are you declaring global variables in any header files? I ask because I'm seeing an `iostream` error but you're not using it anywhere above. – Brandon Feb 11 '15 at 05:59
  • I am not using anything that says "ignore". I have actually not learned any of those yet so I am not sure what they are. – Ana Feb 11 '15 at 06:02
  • 1
    You need to strip down your code before posting, yours is too much and at the same time incomplete. This helps you find errors yourself and allows others to help you. I'm also wondering which compiler and version you are using, I'd expect any modern compiler to recognize and decode these errors. – Ulrich Eckhardt Feb 11 '15 at 06:15
  • @Ana To confirm, when you compile this above code with the command `g++ Card.cpp`, you get the multiple definition errors? If so, I can't reproduce it(after making some simple compilation fixes). – Pradhan Feb 11 '15 at 06:50

1 Answers1

1

What you are seeing are the mangled names of some symbols in your object files. To make sense you them, use c++filt like this:

$ c++filt -n _ZNSi6ignoreE
std::istream::ignore
$ c++filt -n _ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreE
std::basic_istream<wchar_t, std::char_traits<wchar_t> >::ignore

Alright! The names start to look familiar now. So, istream::ignore is present in multiple object files. [To be continued after seeing your build command :)]

Pradhan
  • 16,391
  • 3
  • 44
  • 59
  • I typed it in and it gave me std::basic_istream >::ignore std::basic_istream >::ignore Then tried to compile and the same error showed up again. I don't know why it has a lot of "char"s when I don't have any in my program :( – Ana Feb 11 '15 at 05:22
  • Your command is just `g++ card.cpp`? And you get these errors? I am not sure what to make of it. Would it be possible to show card.cpp? – Pradhan Feb 11 '15 at 05:23