Jump to content
  • Advertisement
Sign in to follow this  
Tsuki no Hikari

Vector issues through multiple source files

This topic is 5465 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

At the moment I'm trying to create a vector of character classes for my basic RPG. At the moment it compiles file until I try a player.push_back(), which gives me a "no matching function for call to `std::vector<Player, std::allocator<Player> >::push_back()'" error. Am I missing something?
// class.h
// This file will declare all classes and class prototypes

#ifndef CLASS_H
#define CLASS_H

#include "enum.h"

class Player
   void playerCreate();

   characterClass cClass;
   elementType    eType;

   char  *name;
   long  hp;          // Must be negative to test if < 0
   long  hpmax;
   long  mp;          // Must be negative to test if < 0
   long  mpmax;
   long  pAttack;     // Physical Attack
   long  pDefense;    // Physical Defense
   int   pEvade;      // % Chance of evading (0-255%)
   int   pLuck;       // % Chance of critical hit (0-75%)
   long  pSpeed;
   long  mAttack;     // Magic Attack
   long  mDefense;    // Magic Defense
   int   mEvade;      // % Chance of evading magical attacks (0-255%)
   int   level;       // (1-1000)
   long  exp;         // (0-1,000,000,000)
   int   kills;       // Number of kills for this character
   long  ap;          // AP for weapon & magic skills

   int incHP;         // 
   int incMP;         // CONSTANT
   int incAttack;     // Values
   int incDefense;    // Used
   int incMagic;      // for
   int incMdef;       // levelUp()
   int incSpeed;      // 

// class.cpp
// This file will initialize all class information

#include <cstdio>
#include <cstdlib>
#include <vector>

#include "class.h"
#include "stardust.h"
#include "enum.h"

   name     = "";
   hp       = 0;   hpmax    = 0;   mp       = 0;   mpmax    = 0;
   pAttack  = 0;   pDefense = 0;   pEvade   = 0;   pLuck    = 0;   
   pSpeed   = 0;   mAttack  = 0;   mDefense = 0;   mEvade   = 0;  
   level    = 0;   exp      = 0;   kills    = 0;   ap       = 0;

void Player::playerCreate(   )

   cClass      = charClassNone;
   eType       = eleNone;
   pAttack     = 0; 
   pDefense    = 0;
   mAttack     = 0;
   mDefense    = 0;
   pSpeed      = 0;
   hpmax = hp  = 0;
   mpmax = mp  = 0;
   incHP       = hpmax - 2;
   incMP       = mpmax - 2;
   incAttack   = pAttack - 2;
   incDefense  = pDefense - 2;
   incMagic    = mAttack - 2;
   incMdef     = mDefense - 2;
   incSpeed    = pSpeed - 2;
   level       = 1;


std::vector<Player> player(6);

// stardust.cpp
// This file will run the main module of the program

#include "class.h"
#include "stardust.h"
#include "enum.h"

#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <vector>

int main(int argc, char *argv[])
   srand( time(NULL) );

   return 0;

And I have another .h file that declares extern std::vector<Player> player; Can anyone help? I'm just getting into vectors and my books really don't go enough into it.

Share this post

Link to post
Share on other sites
push_back() takes a parameter that specifies the object to add to the vector. You're not supplying one. Try changing to code to:
Player thePlayer;

Share this post

Link to post
Share on other sites
Your problem is this line right here (at the top of main in stardust.cpp):


std::vector::push_back takes one argument, which is a const reference to whatever type it's holding. If you want to push back a blank player object, you should do something more like this:


Hope that helps.


Share this post

Link to post
Share on other sites
Man I really feel like I'm in freaking idiot mode today. I'm off a lot.. I didn't even catch the fact that I was calling a function outside of any functions earlier... Man..bed, please give me back my brain..

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!