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 7573577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:13:03+00:00 2026-05-30T16:13:03+00:00

void spawn_enemies(vector<Enemy>& enemies) { I had that function, and it worked just fine to

  • 0
void spawn_enemies(vector<Enemy>& enemies) {

I had that function, and it worked just fine to pass a vector of Enemy’s as an argument.

However, I know have a vector of <Enemy*>‘s, and it doesn’t work so well, and I also tried to use:

void spawn_enemies(vector<Enemy*>& enemies) {

But it didn’t work either, I get the following error on compilation:

src/Paxlure.cpp:32:28: error: no matching function for call to ‘std::vector<Enemy*>::push_back(Enemy&)’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/stl_vector.h:826:7: note: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Enemy*, _Alloc = std::allocator<Enemy*>, std::vector<_Tp, _Alloc>::value_type = Enemy*]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/stl_vector.h:826:7: note:   no known conversion for argument 1 from ‘Enemy’ to ‘Enemy* const&’

Thank you

  • 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-30T16:13:04+00:00Added an answer on May 30, 2026 at 4:13 pm

    If you have a vector of pointers, you need to push_back pointers, not objects.

    vector<Enemy> enemies;
    Enemy e;
    enemies.push_back(e);
    

    versus

    vector<Enemy*> enemies;
    Enemy* pe = new Enemy;
    enemies.push_back(pe);
    

    In the latter case, with dynamically allocated memory, you’ll need to free it yourself: delete pe;. But you have to make sure you correctly manage the memory – don’t delete it before you’re sure the vector will no longer try to work with it. Or simply use smart pointers instead of raw ones.

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

Sidebar

Related Questions

void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I
Say we have a function that does not interfere with other data and runs
void (int a[]) { a[5] = 3; // this is wrong? } Can I
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
void some_func(int param = get_default_param_value());
void FileManager::CloseFile(File * const file) { for (int i = 0; i < MAX_OPEN_FILES;
- (void)viewDidUnload { self.GPSArray = nil; self.accelerometerArray = nil; self.headingArray = nil; self.managedObjectContext =
- (void)applicationDidFinishLaunching:(UIApplication *)application { // Create the navigation and view controllers RootViewController *rootViewController =
-(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSString *theXML = [[NSString alloc] initWithBytes: [myWebData mutableBytes] length:[myWebData length] encoding:NSUTF8StringEncoding];
void BinaryTree::InitializeFromFile(string Filename){ ifstream inFile; treenode* Freq[256]; inFile.open(Filename.c_str(), fstream::binary); if(inFile.fail()){ cout<<Error in opening file

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.