Skip to content

Instantly share code, notes, and snippets.

@ucasfl
Last active October 25, 2021 08:32
Show Gist options
  • Save ucasfl/d1e6c0e5b02af3ce3f86403b1ebdf73d to your computer and use it in GitHub Desktop.
Save ucasfl/d1e6c0e5b02af3ce3f86403b1ebdf73d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
namespace A
{
class Array
{
public:
Array() = default;
void test() { }
Array(Array && array) { a = std::move(array.a); }
Array & operator=(Array && array)
{
a = std::move(array.a);
return *this;
}
std::vector<int> a;
};
class C
{
public:
C() = default;
void setArray(Array * arr_) { arr = std::move(*arr_); }
Array arr;
};
}
namespace B
{
class Array
{
public:
Array() = default;
Array(Array && array) { a = std::move(array.a); }
Array & operator=(Array && array)
{
a = std::move(array.a);
return *this;
}
std::vector<int> a;
};
class C
{
public:
C() = default;
void setArray(Array * arr_) { arr = std::move(*arr_); }
Array arr;
};
}
int main()
{
A::Array arr;
arr.a.push_back(10);
auto b = std::move(arr);
std::cout << arr.a.size() << std::endl;
std::cout << b.a.size() << std::endl;
A::C c1;
c1.arr.a.push_back(10);
c1.arr.a.push_back(10);
c1.arr.a.push_back(10);
B::C c2;
c2.setArray((B::Array *)(&c1.arr));
std::cout << c1.arr.a.size() << std::endl;
std::cout << c2.arr.a.size() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment