Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Strange issue with std::vector


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Chris528   Members   -  Reputation: 186

Like
0Likes
Like

Posted 19 July 2013 - 06:57 PM

I'm getting a really strange error.
I defined std::vector<std::string> m_gamedata; in a class as a member variable.
I created an instance of the class in a function of another class and when i went to use "push_back" i got the following error.
Error 19 error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::push_back' : cannot convert parameter 1 from 'std::string' to 'char' f:\testapps\common\config_handler.h 279

Sponsor:

#2 Pink Horror   Members   -  Reputation: 1227

Like
3Likes
Like

Posted 19 July 2013 - 07:11 PM

Providing code helps others help you.

 

You're calling std::string::push_back. Without the code, I cannot tell you why.



#3 Chris528   Members   -  Reputation: 186

Like
0Likes
Like

Posted 19 July 2013 - 07:12 PM

Providing code helps others help you.
 
You're calling std::string::push_back. Without the code, I cannot tell you why.

std::string pkey1val = pKey1->m_pValue;
current_config->m_gamedata[i].push_back(pkey1val);

Edited by Chris528, 19 July 2013 - 07:12 PM.


#4 Servant of the Lord   Crossbones+   -  Reputation: 20899

Like
5Likes
Like

Posted 19 July 2013 - 07:13 PM

It sounds like you're accidentally accessing the element in the vector, and then calling push_back().

 

std::string also has a push_back() function for pushing back chars onto the string.

 

Maybe you're accidentally doing:

m_gamedata[0].push_back(str); //Incorrect. Calling std::string::push_back()

Instead of:

m_gamedata.push_back(str); //Correct. Calling std::vector::push_back().

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 Chris528   Members   -  Reputation: 186

Like
0Likes
Like

Posted 19 July 2013 - 07:14 PM

It sounds like you're accidentally accessing the element in the vector, and then calling push_back().
 
std::string also has a push_back() function for pushing back chars onto the string.
 
Maybe you're accidentally doing:

m_gamedata[0].push_back(str); //Incorrect. Calling std::string::push_back()
Instead of:[/size]

m_gamedata.push_back(str); //Correct. Calling std::vector::push_back().
Thank you very much, that was it. I'm embarrassed that I missed that, lol.

#6 Servant of the Lord   Crossbones+   -  Reputation: 20899

Like
0Likes
Like

Posted 19 July 2013 - 07:15 PM

std::string pkey1val = pKey1->m_pValue;
current_config->m_gamedata[i].push_back(pkey1val);

Yeah, that's saying:

m_gamedata[i]     //Access the string held at position 'i' inside the vector called m_gamedata.
   .push_back(pkey1val); //Call the 'push_back()' function on the string we just accessed.

[Edit:] Whoops, I keep posting two seconds after you. laugh.png


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS