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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:48:43+00:00 2026-06-02T11:48:43+00:00

I have a simple class and I am using a std::vector to contain all

  • 0

I have a simple class and I am using a std::vector to contain all of the instances of that class. However when I do:

std::vector<MyType> v;
MyType m(1, 2, 3);
v.push_back(m);

Or if I do:

v.push_back(new MyType(1, 2, 3);

I get this error:

error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'MyType *' to 'MyType &&'

And if it is important, here my MyType code:

class MyType
{
public:
  int a;
  int b;
  float c;

MyType(int A, int B, float C)
{
    a = A;
    b = B;
    c = C;
}
};

I don’t understand what is going wrong.

EDIT: My original (first snippet) of code works. For whatever reason I had to rebuild the solution and afterwards it compiled fine.

  • 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-06-02T11:48:45+00:00Added an answer on June 2, 2026 at 11:48 am

    In your code, MyType is a type, while m is an object, so new m(1,2,3) doesn’t even make sense.

    Write:

    v.push_back(MyType(1, 2, 3)); //without new
    

    Instead of push_back, you could also use emplace_back as :

    v.emplace_back(1,2,3); //note there is no `MyType` now
    

    emplace_back is preferable.

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

Sidebar

Related Questions

I have a simple Class Hierarchy that I am trying to get to work
I have a relatively simple class. I serialize it using JDK 1.7 on my
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I have a very simple scenario, using NHibernate: one abstract base class animal; two
I have a simple class that contains some general information about the current web
I have a C++ class that I'm using, and there's a function in it
I have to write a simple log class, that would write the output to
I have this very simple piece of code; #include <deque> #include <vector> using namespace
I have a simple class: class X { std::string S; X (const std::string& s)
I am using John resig's implementation class mentioned here: http://ejohn.org/blog/simple-javascript-inheritance/ Now I have a

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.