C ++:警告:C4930:未调用原型函数(是否要使用变量定义?) [英] C++: warning: C4930: prototyped function not called (was a variable definition intended?)
问题描述
我有一个没有默认构造函数的类,我创建了一个变量而没有错误给出参数,但是我遇到了一个链接器错误,而不是一个不错的编译器错误,我无法
I have a class that does not have a default constructor, I created a variable without giving parameters by mistake, but instead of a nice compiler error, I got a linker error, where I couldn't find the line of code that was causing it.
最后,我设法找到了导致该问题的代码,直到那时我才注意到警告:
In the end, I managed to find the code that caused this, and only then I noticed that I was getting this warning:
C++: warning: C4930: prototyped function not called (was a variable definition intended?)
当我从以下位置更改代码时,很奇怪:
What's weird is when I changed the code from:
MyClass foo();
到
MyClass foo;
我确实遇到了编译器错误。
I did get a compiler error.
有人可以向我解释为什么编译器突然开始表现奇怪,是bug还是什么?
Can someone explain to me why the compiler suddenly started acting strange, is it a bug or something?
推荐答案
此
MyClass foo();
是具有返回类型MyClass且不接受参数的函数声明。
is a function declaration that has return type MyClass and does not accept arguments..
This
MyClass foo;
是对象定义。由于您的类MyClass没有默认的构造函数,因此编译器会发出错误。
is an object definition. As your class MyClass has no the default constructor the compiler issues an error.
这篇关于C ++:警告:C4930:未调用原型函数(是否要使用变量定义?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!