- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试解决将我的构建系统操作系统和 gcc 版本升级到 9 所产生的错误。我可以用下面的代码来演示它。
class Cl {
private:
float f;
public:
constexpr float GetF() const { return f; }
Cl& operator=(const Cl& other) {
f = other.GetF();
return *this;
}
Cl& operator=(const float& other) {
this->f = other;
return *this;
}
explicit constexpr Cl(const float& val) : f(val) {}
};
struct Sl {
float x, y;
Cl lcl;
constexpr Sl(const float &init_x, const float &init_y, const Cl &cl) : x(init_x), y(init_y), lcl(cl) {}
};
typedef struct Sl sdata;
int main()
{
const float fx = 30.30;
Cl c1(fx);
sdata s1(0, 0.0, c1);
return 0;
}
编译:
preetam@preetam-Precision-M4800 ~ $ g++-9 -Werror=deprecated-copy dp_test.cc
dp_test.cc: In constructor ‘constexpr Sl::Sl(const float&, const float&, const Cl&)’:
dp_test.cc:22:101: error: implicitly-declared ‘constexpr Cl::Cl(const Cl&)’ is deprecated [-Werror=deprecated-copy]
22 | constexpr Sl(const float &init_x, const float &init_y, const Cl &cl) : x(init_x), y(init_y), lcl(cl) {}
| ^
dp_test.cc:8:6: note: because ‘Cl’ has user-provided ‘Cl& Cl::operator=(const Cl&)’
8 | Cl& operator=(const Cl& other) {
| ^~~~~~~~
cc1plus: some warnings being treated as errors`
错误的含义是什么?
constexpr Cl(const Cl& other) {
f = other.GetF();
}
它导致了错误:
preetam@preetam-Precision-M4800 ~ $ g++-9 -Werror=deprecated-copy dp_test.cc
dp_test.cc: In copy constructor ‘constexpr Cl::Cl(const Cl&)’:
dp_test.cc:10:9: error: member ‘Cl::f’ must be initialized by mem-initializer in ‘constexpr’ constructor
10 | }
| ^
dp_test.cc:5:9: note: declared here
5 | float f;
| ^
最后用以下复制构造函数修复:
constexpr Cl(const Cl& other) : f(other.f) {}
最佳答案
您正在为 lcl(cl)
使用复制构造函数虽然您没有定义一个,但您定义了一个用户定义的赋值运算符。您可以通过添加用户定义的构造函数来修复它:
class Cl {
private:
float f;
public:
constexpr float GetF() const { return f; }
constexpr Cl(const Cl& other) : f(other.f) { }
Cl& operator=(const Cl& other) {
f = other.GetF();
return *this;
}
Cl& operator=(const float& other) {
this->f = other;
return *this;
}
explicit constexpr Cl(const float& val) : f(val) {}
};
struct Sl {
float x, y;
Cl lcl;
constexpr Sl(const float &init_x, const float &init_y, const Cl &cl) : x(init_x), y(init_y), lcl(cl) {}
};
typedef struct Sl sdata;
int main()
{
const float fx = 30.30;
Cl c1(fx);
sdata s1(0, 0.0, c1);
return 0;
}
挑剔:“错误的含义是什么?”这不是错误而是警告。该项目可以编译并按预期运行,但当然,问题应该得到解决。
关于c++ - gcc/g++ 错误 'implicitly-declared' 构造函数是 'deprecated' 的含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66115771/
这个问题在这里已经有了答案: How to declare or mark a Java method as deprecated? (6 个回答) 关闭8年前。 我可以使用 @Deprecated
我要使用的代码: window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) 有FLAG_SHOW_WHEN_LOCKED在 A
这个问题已经有答案了: Can I mix MySQL APIs in PHP? (4 个回答) Why shouldn't I use mysql_* functions in PHP? (14 个
我在我的网站上看到以下消息,我该怎么办? Deprecated: Function eregi() is deprecated in D:\wamp\www\cidoc.gov.mz\modules\
我正在弃用一组 Java 类,以便不再使用它们。我不想关闭不推荐使用的编译器警告,但我发现如果我的一个不推荐使用的类导入另一个不推荐使用的类,我也会收到警告。我不想修改我不赞成使用的代码,但我也不想在
这个问题在这里已经有了答案: How to use Ansible's with_item with a variable? (1 个回答) 3年前关闭。 我认为这是产生错误的剧本的一部分。我应该如何
在我的 Eclipse Indigo 中,只有 @Deprecated 有效,但 @deprecated 在评论中无效,知道吗? 例如 // @deprecated <-- not work @Dep
This question already has answers here: How can I convert ereg expressions to preg in PHP? (4个答案) 去年
我正在将代码从以前版本的 Swift 更改为 Swift5。并且有一条警告消息表明此代码不可用。我想更改此代码,但不知道如何更改。 警告代码 func pbkdf2(hash: CCPBKDFAlg
我正在开发使用 Game Center 的游戏,但我收到了下一个警告; ... 'authenticateWithCompletionHandler:' 已弃用:首先在 iOS 6.0 中弃用 好的,
您好,我在错误日志中收到此错误: "PHP 已弃用:自动填充 $HTTP_RAW_POST_DATA 已弃用,并将在未来版本中删除。为避免此警告,请在 php.ini 中将 'always_popul
您好,我在错误日志中收到此错误: "PHP 已弃用:自动填充 $HTTP_RAW_POST_DATA 已弃用,并将在未来版本中删除。为避免此警告,请在 php.ini 中将 'always_popul
CC_MD5 已在 ios14 中弃用,但我的项目至少支持 ios14。我仍然需要 MD5。我应该怎么办?我使用的开发语言是OC 最佳答案 MD5 已被弃用,因为它是一种有缺陷、不安全的算法。如果可以
我在 Xcode 上的这个条目上有以下问题: CLRegion *pushRegion = [[CLRegion alloc] initCircularRegionWithCenter:coordin
所以我有一个代码可以开始录制音频并不断收到上述警告消息。有帮助吗? - (IBAction)recordStart:(id)sender { AVAudioSession *recSessio
我制作了这个返回文档目录中文件大小的函数,它可以工作,但我得到警告,我想修复,函数: -(unsigned long long int)getFileSize:(NSString*)path { NS
我收到警告: >typings ls typings WARN deprecated 2016-08-05: "registry:dt/react#0.14.0+20160423065914" is
问题的表述有点奇怪,但我想要的是 Rspec 中 stub! 的替代方案,它不会产生弃用警告。 场景: 我使用 stub! 在我的帮助程序规范中对某些帮助程序方法进行 stub 。 例如 stub!(
最近我将我的 Rails 版本从 3.2 迁移到 4.2.6,同时我修改了一些 gem,例如回形针 2.3 到 4.3.6。当我运行 rails server 时,我得到以下弃用: DEPRECATI
My Goal: To fix this error and be able to run my app without an error. Error Message: Note:D:\Learni
我是一名优秀的程序员,十分优秀!