I get the following error when trying to use:
typedef QSharedPointer<Test> CTest
CTest* Module::function(params)
{
CTestNew* ptr = new CTestNew(params);
dosomething();
return ptr;
}
Then replace Test* with CTest in the code. What am I missing?
error C2664: 'QSharedPointer<T>::QSharedPointer(const QSharedPointer<T> &)' : cannot convert parameter 1 from 'CTestNew*' to 'const QSharedPointer<T> &'
with
[
T=Test
]
Reason: cannot convert from 'CTestNew *' to 'const QSharedPointer<T>'
with
[
T=Test
开发者_开发知识库 ]
Constructor for class 'QSharedPointer<T>' is declared 'explicit'
with
[
T=Test
]
Compiler error's saying that CTestNew
isn't the same as Test
EDIT: In response to comments saying CTestNew
is a subclass of the abstract Test
CTest* Module::function(params)
{
CTestNew* ptr = new CTestNew(params);
dosomething();
return ptr;
}
should be:
CTest Module::function(params) // Don't return a pointer to a shared pointer
{
Test * ptr = new Test(params); // You're using Test not CTestNew in the CTest typedef
dosomething();
return CTest(static_cast<Test *>(ptr));
}
精彩评论