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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:06:24+00:00 2026-06-09T07:06:24+00:00

I have some code: Class A{ //…A has a move ctor here. }; unordered_map<int,

  • 0

I have some code:

Class A{
//...A has a move ctor here.
};

unordered_map<int, A> bla;
A tmp;
//operations on tmp
bla.insert(make_pair<int, A>(1, move(tmp)));

I wanna call move constructor instead of copy ctor of class A. Is this code correct?
I think so. The weird thing is it compiles and works for Ubuntu Precise (g++ show version of 4.6.3). But on CentOS, it failed to compile. The first few lines are:

 In substitution of ‘template<class _From1, class _To1> static decltype     ((__test_aux<_To1>(declval<_From1>()), std::__sfinae_types::__one()))     std::__is_convertible_helper<_From, _To, false>::__test(int) [with _From1 = _From1; _To1 = _To1; _From = const A&; _To = A] [with _From1 = const A&; _To1 = A]’:
/gcc/x86_64-redhat-linux/4.7.1/../../../../include/c++/4.7.1/type_traits:1258:70:   required from ‘constexpr const bool std::__is_convertible_helper<const A&, A, false>::value’
/gcc/x86_64-redhat-linux/4.7.1/../../../../include/c++/4.7.1/type_traits:1263:12:   required from ‘struct std::is_convertible<const A&, A>’
/gcc/x86_64-redhat-linux/4.7.1/../../../../include/c++/4.7.1/type_traits:116:12:   required from ‘struct std::__and_<std::is_convertible<const int&, int>, std::is_convertible<const A&, A> >’
/gcc/x86_64-redhat-linux/4.7.1/../../../../include/c++/4.7.1/bits/stl_pair.h:113:38:   required from ‘constexpr std::pair<typename std::__decay_and_strip<_T1>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = A; typename std::__decay_and_strip<_T2>::__type = A; typename std::__decay_and_strip<_T1>::__type = int]’

It seems trying to call copy ctor. Any ideas on this error?

Well, my CentOS does not have recent version of gcc/libstdc++, so actually i build these(gcc 4.7.1) by myself and install them in my home dir. Does this matter? This is my configuration when compiling:

Target: x86_64-redhat-linux
Configured with: ../gcc-4.7.1/configure --prefix=/home/bla/usr/ --with-mpc=/home/bla/usr/ --with-mpfr=/home/bla/usr/ --with-gmp=/home/bla/usr/ --disable-multilib --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++ --enable-java-awt=gtk --disable-dssi --disable-plugin --with-cpu=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.7.1 (GCC)

UPDATE:
Maybe there is sth wrong with the usage of “move semantic”. I tried “move” with STL string:

unordered_map<int, string> bla;
string tmp("hello world");
//operations on tmp
bla.emplace(1, move(tmp));

It is just ok and the internal chars are really “moved”.

But it does NOT work with my class A… This is A:

class A
{
    public:
        A(){...}
        ~A(){}
        A(A&& other){...}
    private:
        A& operator = (const A& other);
        A& operator = ( A&& other);
        A(const A& other);
};

UPDATE:
i got it work, when A is:

class A
{
    public:
        A(){...}
        ~A(){}
        A(A&& other){...}
        A(const A& other){}
    private:
        A& operator = (const A& other);
        A& operator = ( A&& other);
};

Pay attention to the COPY CTOR. Now all my move semantic works correct and copy ctor is not actually called when running. Do i get sth wrong about “move”?

  • 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-09T07:06:26+00:00Added an answer on June 9, 2026 at 7:06 am

    I believe that this question has the same answer as this question and could be a duplicated question.

    However, i still have not successfully compile it when using noexcept keyword with move contstructor.

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

Sidebar

Related Questions

I have some Java code: public class Car { private int yearModel; private String
Suppose I have some code like this: class Base { public: virtual int Foo(int)
I have some code here (my activity class and some class, that extends WebViewClient)
I have some code that has a dynamic-class system in C++ that has a
i have some code in Ruby here below: class A @@lock = Monitor.new class
Say I have some code like this: class Foo { public: Foo(int v) :
I have some code in a reusable class that modifies some types. Here's a
I have some questions with relationship of ef code first. My code: public class
I have some C++ code #include <cstdio> #include <boost/bind.hpp> #include <boost/function.hpp> class A {
I am looking to do some method chaining. I have the following code: class

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.