KGC*_*beX 5 c++ qt struct class
首先到达这个问题,我看了几个SO问题,其中一半似乎不适用,另一半,坦率地说,我只是不遵循.
问题:
这是我的问题的简单实现,
错误:未定义模板'QList
<VPNConnection>'的隐式实例化
具体来说,VPNListstruct中的对象User_VPN_Info带有上述错误的下划线.
值得注意的是,在一篇文章中提到让你的"孩子"在父母之上,否则就会实现一种原型,因此就是VPNConnection在原型之上User_VPN_Info.
基本说明:
该结构User_VPN_Info应实施结构VPNConnection中的QList的形式持有多VPNConnection的
裸码:
struct VPNConnection{
QString ip,cipher,protocol;
int port;
bool lzo_compression;
VPNConnection(){}
VPNConnection(QString _ip, QString _cipher, QString _protocol, int _port, bool _comp){
ip = _ip;
cipher = _cipher;
protocol = _protocol;
port = _port;
lzo_compression = _comp;
}
};
struct User_VPN_Info{
QString vpn_name, vpn_expire;
int DaysLeft;
QList<VPNConnection> VPNList;
-------- <<< --- underlined with error
User_VPN_Info(){}
User_VPN_Info(QString _vpn_name, QString _vpn_expire, int _DaysLeft){
vpn_name = _vpn_name;
vpn_expire = _vpn_expire;
DaysLeft = _DaysLeft;
}
QString getString(){
return(vpn_name + " + " + vpn_expire + " + " + QString::number(DaysLeft) + " ; ");
}
};
Run Code Online (Sandbox Code Playgroud)
我想了解导致此错误的原因以及为什么会出现此错误?
错误:未定义模板'QList
<VPNConnection>'的隐式实例化
UPDATE
经过一些更多的研究,我得到了这个
用户 - dasblinkenlight
适用于指针
因此改为:
QList<VPNConnection> *VPNList;
Run Code Online (Sandbox Code Playgroud)
删除了这个问题.
有人愿意提供解释吗?
Haz*_*maa 10
那是因为你没有包含QList标题,所以你缺少QList的定义,如果你有一个这种类型的变量你需要它
QList<VPNConnection> VPNList;
Run Code Online (Sandbox Code Playgroud)
但是,似乎您包含一些使QList标识符可用的标头(例如QString).否则,您将收到错误消息
未知类型名称QList
这解释了为什么使用指针的解决方案工作正常,因为它只需要向前声明QList.