Skip to content

w3b5h3ll/CS106L

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CS106L

"Standard C++ Programming" course learning...

Assignments

暂时没有06, 07的starter code

  • Assignment 01: SimpleEnroll
  • Assignment 02: Marriage Pact
  • Assignment 03: Make a Class
  • Assignment 04: Weather Forecast
  • Assignment 05: TreeBook

尝试使用std::move()进行右值转换,但是内部调用set的insert操作还是使用了copy constructor,如下

int main()
{

    // create a bunch of users
    User alice("Alice");
    User bob("Bob");
    User charlie("Charlie");
    User dave("Dave");

    // make them friends
    // alice = alice + bob;
    alice = std::move((alice) + bob);
    alice = std::move((alice) + charlie);

    dave = std::move((dave) + bob);
    charlie = std::move((charlie) + dave);

    // print out their friends
    printFriends(alice);
    printFriends(bob);
    printFriends(charlie);
    printFriends(dave);

    return 0;
}

报错

user.cpp:47:23:   required from here
   47 |     lhs.friends.insert(rhs.friends.begin(), rhs.friends.end());
      |     ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14.1.1/bits/new_allocator.h:191:11: 错误:使用了被删除的函数‘User::User(const User&)’
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
user.h:10:5: 附注:在此声明
   10 |     User(const User &) = delete;
      |     ^~~~
/usr/include/c++/14.1.1/bits/new_allocator.h:191:11: 附注:use ‘-fdiagnostics-all-candidates’ to display considered candidates
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }

About

"Standard C++ Programming

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published