只是遇到了代码的编译错误,试图模拟一个std::weak_ptr
作为参数的方法。HippoMocks
在调用方法时有一个代码来比较它With
,它不会被编译。我将不胜感激任何帮助。
这是代码:
struct SomeClass {
SomeClass(){};
void someMethod(std::weak_ptr<int> d) {}
};
bool operator == (const std::weak_ptr<int> lhs, const std::weak_ptr<int> rhs) {
return *(lhs.lock()) == *(rhs.lock());
}
BOOST_AUTO_TEST_CASE(test_weak_ptr)
{
SomeClass obj;
std::weak_ptr<int> data = std::make_shared<int>(new int(15));
HippoMocks::MockRepository mocks;
mocks.ExpectCall(&obj, SomeClass::someMethod).With(data);
}
MS VS 2010 编译器不喜欢最后一行并抱怨:
d:\hippomocks\hippomocks.h(398): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const std::tr1::weak_ptr<_Ty>' (or there is no acceptable conversion)
with
[
_Ty=int
]
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\guiddef.h(192): could be 'int HippoMocks::operator ==(const HippoMocks::GUID &,const HippoMocks::GUID &)'
while trying to match the argument list '(const std::tr1::weak_ptr<_Ty>, const std::tr1::weak_ptr<_Ty>)'
with
[
_Ty=int
]
d:\hippomocks\hippomocks.h(397) : while compiling class template member function 'bool HippoMocks::comparer<T>::compare(const std::tr1::weak_ptr<_Ty>,const std::tr1::weak_ptr<_Ty>)'
with
[
T=std::tr1::weak_ptr<int>,
_Ty=int
]
d:\hippomocks\hippomocks.h(650) : see reference to class template instantiation 'HippoMocks::comparer<T>' being compiled
with
[
T=std::tr1::weak_ptr<int>
]
d:\hippomocks\hippomocks.h(649) : while compiling class template member function 'bool HippoMocks::copy_tuple<A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,CA,CB,CC,CD,CE,CF,CG,CH,CI,CJ,CK,CL,CM,CN,CO,CP>::operator ==(const HippoMocks::ref_tuple<A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P> &)'
with
[
A=std::tr1::weak_ptr<int>,
B=HippoMocks::NullType,
C=HippoMocks::NullType,
D=HippoMocks::NullType,
E=HippoMocks::NullType,
F=HippoMocks::NullType,
G=HippoMocks::NullType,
H=HippoMocks::NullType,
I=HippoMocks::NullType,
J=HippoMocks::NullType,
K=HippoMocks::NullType,
L=HippoMocks::NullType,
M=HippoMocks::NullType,
N=HippoMocks::NullType,
O=HippoMocks::NullType,
P=HippoMocks::NullType,
CA=const std::tr1::weak_ptr<int> &,
CB=HippoMocks::NullType,
CC=HippoMocks::NullType,
CD=HippoMocks::NullType,
CE=HippoMocks::NullType,
CF=HippoMocks::NullType,
CG=HippoMocks::NullType,
CH=HippoMocks::NullType,
CI=HippoMocks::NullType,
CJ=HippoMocks::NullType,
CK=HippoMocks::NullType,
CL=HippoMocks::NullType,
CM=HippoMocks::NullType,
CN=HippoMocks::NullType,
CO=HippoMocks::NullType,
CP=HippoMocks::NullType
]
d:\hippomocks\hippomocks.h(2985) : see reference to class template instantiation 'HippoMocks::copy_tuple<A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,CA,CB,CC,CD,CE,CF,CG,CH,CI,CJ,CK,CL,CM,CN,CO,CP>' being compiled
with
[
A=std::tr1::weak_ptr<int>,
B=HippoMocks::NullType,
C=HippoMocks::NullType,
D=HippoMocks::NullType,
E=HippoMocks::NullType,
F=HippoMocks::NullType,
G=HippoMocks::NullType,
H=HippoMocks::NullType,
I=HippoMocks::NullType,
J=HippoMocks::NullType,
K=HippoMocks::NullType,
L=HippoMocks::NullType,
M=HippoMocks::NullType,
N=HippoMocks::NullType,
O=HippoMocks::NullType,
P=HippoMocks::NullType,
CA=const std::tr1::weak_ptr<int> &,
CB=HippoMocks::NullType,
CC=HippoMocks::NullType,
CD=HippoMocks::NullType,
CE=HippoMocks::NullType,
CF=HippoMocks::NullType,
CG=HippoMocks::NullType,
CH=HippoMocks::NullType,
CI=HippoMocks::NullType,
CJ=HippoMocks::NullType,
CK=HippoMocks::NullType,
CL=HippoMocks::NullType,
CM=HippoMocks::NullType,
CN=HippoMocks::NullType,
CO=HippoMocks::NullType,
CP=HippoMocks::NullType
]
d:\unittests\test.cpp(31) : see reference to function template instantiation 'HippoMocks::TCall<Y,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P> &HippoMocks::TCall<Y,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P>::With<std::tr1::weak_ptr<_Ty>>(const CA &)' being compiled
with
[
Y=void,
A=std::tr1::weak_ptr<int>,
B=HippoMocks::NullType,
C=HippoMocks::NullType,
D=HippoMocks::NullType,
E=HippoMocks::NullType,
F=HippoMocks::NullType,
G=HippoMocks::NullType,
H=HippoMocks::NullType,
I=HippoMocks::NullType,
J=HippoMocks::NullType,
K=HippoMocks::NullType,
L=HippoMocks::NullType,
M=HippoMocks::NullType,
N=HippoMocks::NullType,
O=HippoMocks::NullType,
P=HippoMocks::NullType,
_Ty=int,
CA=std::tr1::weak_ptr<int>
]