开发者

overloaded ‘QString(int)’ is ambiguous

开发者 https://www.devze.com 2023-03-22 10:09 出处:网络
The following code fragment gives the compilation error call of overloaded ‘QString(int)’ is ambiguous with qt 4.7.3

The following code fragment gives the compilation error call of overloaded ‘QString(int)’ is ambiguous with qt 4.7.3 (system is linux 64bit, debian unstable)

struct QSAConnection
{
  QSAConnection() : sender(0), signal(0), function_ref() { }
  QSAConnection(QObject *send, const char *sig, QSObject ref)
    : sender(send), signal(Q开发者_如何学编程Latin1String(sig)), function_ref(ref) { }
  QObject *sender;
  QString signal;
  QSObject function_ref;
};

Any tips?


The relevant bit is this line:

QSAConnection() : sender(0), signal(0), function_ref() { }

Since signal is a QString, the signal(0) bit is trying to call a constructor on the QString class that takes an integer as its only parameter. QString has no such constructor according to the Qt documentation. It does however have a constructor taking a char, and a QChar which has an implicit conversion from int. I expect it's ambiguous between those two.

Did you mean this instead?

QSAConnection() : sender(0), signal(), function_ref() { }

Which will default initialize signal. Note that technically it's not necessary to include it in the initializer list at all in that case.


It's a good thing. If it was not ambiguous, you might hit a null-pointer exception on QString::QString(char const* src). This is a common mistake with std::string.

0

精彩评论

暂无评论...
验证码 换一张
取 消