小编Dae*_*mon的帖子

引用c ++中的引用

我正在阅读c ++中的参考概念,我对C++ Complete Reference中的这个陈述感到困惑.

您无法引用其他参考

那么在这种情况下发生了什么:

    int  var = 10;
    int& ref = var;
    int& r_ref = ref;
    r_ref++;
    cout << "var:" << var << "ref:" << ref << "r_ref:" << r_ref << endl;
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

var:11  ref:11  r_ref:11
Run Code Online (Sandbox Code Playgroud)

c++

7
推荐指数
2
解决办法
3395
查看次数

使用Gmock模拟参数化构造函数

我有类被嘲笑但它没有默认构造函数.我无法更改源代码.那么有没有办法使用Gmock模拟参数化构造函数

c++ constructor mocking googletest gmock

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

如何恢复已删除的 .git/modules 文件夹

在我的项目中 .git/modules 文件夹被删除。现在我可以将父分支重置为其他版本,但子模块更新不起作用。

我收到的错误:

fatal: Not a git repository: ../.git/modules/abc.
Unable to find current revision in submodule path 'abc'
Run Code Online (Sandbox Code Playgroud)

如何恢复已删除的文件夹并使子模块恢复与父分支一致。

回购结构是这样的:

parent_folder---|---abc
                |---def
Run Code Online (Sandbox Code Playgroud)

abc 和 def 是子模块。

git git-submodules

5
推荐指数
1
解决办法
4101
查看次数

如果包含析构函数,则类的大小会增加

class MyClass {
        int data;
        public:
        MyClass() : data(0) { /*cout << "Ctor" << endl;*/}
        void* operator new(size_t sz) { cout << "Size in new: " << sz << endl; void* s = malloc(sz); return s; }
        void* operator new[] (size_t sz) { cout << "Size: " << sz << endl; void* s = malloc(sz); return s; }

        void operator delete(void* p) { free(p); }
        void operator delete[](void* p) { free(p); }
        ~MyClass() {}
};
int main() {
        // your …
Run Code Online (Sandbox Code Playgroud)

c++ destructor operator-overloading sizeof new-operator

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

Google Mock实际函数调用计数与EXPECT_CALL不匹配

我是Google Mock的新手,正在尝试使用此代码,我也检查了此链接.

实际函数调用计数与EXPECT_CALL不匹配(*mock,display())

但无法获得适当的输入.

Base.cc

class Base
{
    int val;
    string msg;
    public:
    Base():val(0), msg("world"){}
    virtual ~Base(){}
    virtual void set(int x, string msg)
    {
            this->val = val;
            this->msg = msg;
    }
    virtual void get()
    {
            cout << "val    :" << this->val << endl;
            cout << "msg    :" << this->msg << endl;
    }
};
class MockBase : public Base
{
    public:
    MOCK_METHOD0(get, void());
    MOCK_METHOD2(set, void(int val, string msg));
};
Run Code Online (Sandbox Code Playgroud)

Base_unittest.cc

int main(int argc, char * argv[])
{
    std::cout << "in main" …
Run Code Online (Sandbox Code Playgroud)

c++ mocking googletest googlemock

0
推荐指数
1
解决办法
4379
查看次数