Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6167245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:28:37+00:00 2026-05-23T22:28:37+00:00

I have a function with the following declaration: void playCard(string card); and the following

  • 0

I have a function with the following declaration:

void playCard(string card);

and the following implementation:

void Player::playCard(string card)
{
    cout << "Playing " << card << "!" << endl;

    // Find iterator representing the card to be played
    vector<Card*>::iterator iter;
    for(iter = hand.begin(); iter != hand.end(); iter++)
    {
        if( (*iter)->getName() == card)
            continue;
    }

    // ERROR - Card not found in hand
    if(iter == hand.end())
        assert(false);

    // more stuff
}

The function is called from the following block of code:

// Divide string into 2 words
istringstream iss(in, istringstream::in);
string command, target;
iss >> command >> target;

if(command == "play")
{
    players.at(currentTurn)->playCard(target);
}

players is declared as:

vector<Player*> players;

The problem I’m having is that no matter what the “card” string is, I hit the card not found assertion. According to gdb:

Breakpoint 1, Player::playCard (this=0xb3a010, card=0x28ca00) at Player.cpp:138
138         cout << "Playing " << card << "!" << endl;
(gdb) print card
$1 = (string *) 0x28ca00

So within the playCard() function, the card variable is a pointer for some reason. Interestingly enough, the cout statement still displays the contents of the string correctly. Right before calling playCard(), the variable is NOT a pointer according to gdb, just an ordinary string.

Also, this is interesting:

(gdb) print iter
$1 = {_M_current = 0xb9a328}
(gdb) print iter->getName()
Couldn't find method __normal_iterator<Card**,std::vector<Card*, std::allocator<Card*> > >::getName
(gdb) print *iter
$2 = (class Card *&) @0xb9a328: 0xb9a160
(gdb) print *iter->getName()
Couldn't find method __normal_iterator<Card**,std::vector<Card*, std::allocator<Card*> > >::getName
(gdb) print (*iter)->getName()

Program received signal SIGSEGV, Segmentation fault.
0x61111178 in memcpy () from /usr/bin/cygwin1.dll

So gdb causes a segfault when I try to print out that last one, but the same code executes without any segfaults.

I have a feeling I’m dealing with some weird memory issues related to having a vector full of pointers to objects, but I can’t quite put my finger on it.

What’s going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:28:39+00:00Added an answer on May 23, 2026 at 10:28 pm

    You want break instead of continue inside the loop.

    They’re kind of similar; continue means continue with the next iteration of the loop, break means break out of the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function with the following declaration: void cleanValid(int valid[][4], int &size, int
I have faced the following interview question. Consider this function declaration: void quiz(int i)
I have the following function defined inside my linked list class. The declaration in
Let's say we have the following method declaration: Public Function MyMethod(ByVal param1 As Integer,
I have the following function void initBoard(int * board[BOARD_ROWS][BOARD_COLS]){ int z = 0; for(
Suppose we have the following: void print() { int a; // declaration a =
I have the following declaration for SHChangeNotify : [DllImport(Shell32.dll)] public static extern void SHChangeNotify(HChangeNotifyEventID
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function that is pulling data from a database. The ajax
I have the following function: //Function to get random number public static int RandomNumber(int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.