gpt4 book ai didi

c++ - 声明和定义不匹配

转载 作者:行者123 更新时间:2023-12-02 09:54:50 25 4
gpt4 key购买 nike

我的模板类中的声明和定义不匹配(所有不相关的内容都被删除了):

template <typename LanguageMap>
class WidgetLanguageManager
{
public:
enum class Language { DE, ENG, PL };
protected:
Language language;
//Some protected fields
public:
explicit WidgetLanguageManager(const Language& language);
explicit WidgetLanguageManager(const QString& language);
Language ToLanguage(const QString& language);
protected:
//some protected methods
};


template <typename LanguageMap>
Language WidgetLanguageManager<LanguageMap>::ToLanguage(const QString& language) // this cannot be matched with a declaration
{
for (QChar& c: language)
{
c = c.toLower();
}

switch (language)
{
case "german": return Language::DE;
case "english": return Language::ENG;
case "polish": return Language::PL;
}
throw RuntimeError("Wrong language paremeter.");
}


请帮忙,因为我看不到任何原因。

最佳答案

以下将工作:

template <typename LanguageMap>
typename WidgetLanguageManager<LanguageMap>::Language WidgetLanguageManager<LanguageMap>::ToLanguage(const QString& language)
// ^^^^^ 'typename' keyword needed because 'Language' is dependent name

由于 enum class LanguageWidgetLanguageManager模板类的一部分,因此您需要在它前面加上作用域运算符。

关于c++ - 声明和定义不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61074571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com