简体   繁体   English

qt应用程序和std :: shared_ptr

[英]qt application and std::shared_ptr

I want to create a qt application ( using qt-creator ), that use my library, that was build in VS2010. 我想创建一个Qt应用程序(使用qt-creator),该应用程序使用在VS2010中构建的库。 A library contains a class, that use std::shred_ptr<> 一个库包含一个使用std :: shred_ptr <>的类

#include <memory>
struct MyStruct;

class MyClass
{
    public:
    MyClass::MyClass();

    protected:
    std::shared_ptr<MyStruct> mMember;
}

Then I include library to the application, using This tutorial . 然后,使用本教程将库包含到应用程序中。 And gets next errors: 并得到下一个错误:

ISO C++ forbids declaration of 'shared_ptr' with no type
invalid use of '::'
expected ';' before '<' token

Is a way to solve this problem? 有办法解决这个问题吗?

* PS *Was corrected code( added include and parameter class of shared_ptr ). * PS *经过更正的代码(添加了shared_ptr的include和parameter类)。 But this things already been in original code. 但是这些东西已经在原始代码中了。 I think, the problem in the qt-creator compiler. 我认为这是qt-creator编译器中的问题。 But I don't know exactly, because I'm pretty new in qt programming. 但是我不完全知道,因为我在qt编程中很新。

Make sure you use C++11 flag for compiler. 确保对编译器使用C ++ 11标志。 For example, in your .pro -file: 例如,在您的.pro -file中:

QMAKE_CXXFLAGS += -std=c++0x

There's no definition of MyClass2 int the code you shared. 您共享的代码没有MyClass2 int的定义。

I believe you were trying to do std::shared_ptr<MyClass> mMember; 我相信您正在尝试做std::shared_ptr<MyClass> mMember;

Include <memory> before defining the class. 在定义类之前,请包括<memory> Also make sure MyClass2 is declared. 还要确保声明了MyClass2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM