小编All*_*lan的帖子

如何在C++中使用operator = with匿名对象?

我有一个带有重载运算符的类:

IPAddress& IPAddress::operator=(IPAddress &other) {
    if (this != &other) {
        delete data;
        this->init(other.getVersion());
        other.toArray(this->data);
    }
    return *this;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时:

IPAddress x;
x = IPAddress(IPV4, "192.168.2.10");
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

main.cc: In function ‘int main()’:
main.cc:43:39: error: no match for ‘operator=’ in ‘x = IPAddress(4, ((const std::string&)(& std::basic_string<char>(((const char*)"192.168.2.10"), ((const std::allocator<char>&)((const std::allocator<char>*)(& std::allocator<char>())))))))’
IPAddress.h:28:20: note: candidate is: IPAddress& IPAddress::operator=(IPAddress&)
Run Code Online (Sandbox Code Playgroud)

但是,这两个工作正常(虽然它们不能为我服务):

IPAddress x;
IPAddress(IPV4, "192.168.2.10") = x;
Run Code Online (Sandbox Code Playgroud)

-

IPAddress x;
x = *(new IPAddress(IPV4, "192.168.2.10"));
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?我假设分配算子的工作方式不正确吗?

c++ methods operator-overloading

4
推荐指数
1
解决办法
222
查看次数

如何完全删除合并的拉取请求?

我在GitHub上合并了一个pull请求.但是,这是一个错误,我想撤消合并,它的提交,最重要的是,从历史记录中删除这些提交引入的所有文件.

我用另一个恢复提交并且它可以工作,但文件仍然在提交历史中(它们很大)如果提交本身消失将会很好.

我试图过滤分支删除文件,但它似乎没有缩小存储库大小(并且提交仍然存在).

我该怎么办?

git merge github pull-request

2
推荐指数
1
解决办法
7651
查看次数

标签 统计

c++ ×1

git ×1

github ×1

merge ×1

methods ×1

operator-overloading ×1

pull-request ×1