C++: warning: C4930: prototyped function not called (was a variable definition intended?) [duplicate]

泪湿孤枕 提交于 2019-11-27 03:27:43

问题


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();

to

MyClass foo;

I did get a compiler error.

Can someone explain to me why the compiler suddenly started acting strange, is it a bug or something?


回答1:


This

MyClass foo();

is a function declaration that has return type MyClass and does not accept arguments..

This

MyClass foo;

is an object definition. As your class MyClass has no the default constructor the compiler issues an error.



来源:https://stackoverflow.com/questions/20264530/c-warning-c4930-prototyped-function-not-called-was-a-variable-definition-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!