为什么我不能使用 smart-pointer 来制作新的 QLineEdit class
why i can't use the smart-pointer to make a new QLineEdit class
如标题所示,我想为 smart-pointer 的 QLineEdit class 使用一些缓冲区,但编译器显示 "invaild application of 'sizeof' to incomplete type 'QLineEdit'"。我通过构建消息找到了 'aligned_buffer.h' 文件。但很无奈。我感到困惑的是,当我使用相同的方式为 QTextEdit 使用一些缓冲区时,编译器是成功的。为什么 QLineEdit 不能使用相同的方式来做到这一点?
...
shared_ptr<QTextEdit> t1 = make_shared<QTextEdit>(); // successd
shared_ptr<QLineEdit> t2 = make_shared<QLineEdit>(); // failed
...
正确包含头文件
#include <QTextEdit> // https://doc.qt.io/qt-5/qlineedit.html
#include <QLineEdit> // https://doc.qt.io/qt-5/qtextedit.html
#include <memory> //https://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared
int main(){
shared_ptr<QTextEdit> t1 = std::make_shared<QTextEdit>();
shared_ptr<QLineEdit> t2 = std::make_shared<QLineEdit>();
}
如标题所示,我想为 smart-pointer 的 QLineEdit class 使用一些缓冲区,但编译器显示 "invaild application of 'sizeof' to incomplete type 'QLineEdit'"。我通过构建消息找到了 'aligned_buffer.h' 文件。但很无奈。我感到困惑的是,当我使用相同的方式为 QTextEdit 使用一些缓冲区时,编译器是成功的。为什么 QLineEdit 不能使用相同的方式来做到这一点?
...
shared_ptr<QTextEdit> t1 = make_shared<QTextEdit>(); // successd
shared_ptr<QLineEdit> t2 = make_shared<QLineEdit>(); // failed
...
正确包含头文件
#include <QTextEdit> // https://doc.qt.io/qt-5/qlineedit.html
#include <QLineEdit> // https://doc.qt.io/qt-5/qtextedit.html
#include <memory> //https://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared
int main(){
shared_ptr<QTextEdit> t1 = std::make_shared<QTextEdit>();
shared_ptr<QLineEdit> t2 = std::make_shared<QLineEdit>();
}