fix-universal-reference-and-perfect-forwarding-bug #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在阅读代码时发现代码中的完美转发是有问题的:因为模板类的成员方法只是一个普通的函数,并不是一个模板函数,所以他们的参数不会触发类型推导,所以对于T&&类型只是一个普通的右值引用。原本的代码只能接收右值引用参数,但是这显然不是代码的本意,因为后面使用了std::forward进行完美转发,因此应该是一个universal reference才对。测试代码如下:
对于支持多线程实现同样也存在类似的问题。通过将
connect
和call
函数都转换为模板成员函数就可以解决这个问题。