Compiler warning at C++ template base class -


I get a compiler warning that I do not understand that context. When I compile "Child.cpp" with the following code (Do not wonder: I have stripped the declaration of my class from the minimum, so the content does not matter much, but you will see this problem sharp). I get a warning with the highest warning level.


code

AbstractClass.h:

  # include & lt; Iostream & gt; Template & lt; Typename T & gt; Class abstract claus {public: cancel virtual zeros (); // {std :: cout & lt; & Lt; "Cancel Abuse" & lt; & Lt; Std :: endl; }; Virtual Zero Process () = 0; }; // External Definition If I comment on this and take the definition of // above (currently commented), then I could not find a compiler warning // // Template & lt; Typename T & gt; Zero object class & lt; T & gt; :: Cancel () {std :: cout & lt; & Lt; "Cancel Abuse" & lt; & Lt; Std :: endl; }  

Child.h:

  #include "abstractclass.h" class child: Public Abberclus & lt; Int & gt; {Public: Virtual Zero Process (); };  

Child.cpp:

  #include "child.h" # include & lt; Iostream & gt; Zero Child :: Process () {std :: cout & lt; & Lt; "Process" & lt; & Lt; Std :: endl; }  

Warning

The class "child" is taken from "abstlast". The public method in "Abstract" is "abstclass :: cancel ()" if I define the method outside the orbit of the class (as the code you see), I get a compiler warning ...

AbstractClass.h (7): Warning C4505: 'abstractClass:: Cancel': Removed the local function without reference [T = int]

. When I compile "Child.cpp". I do not understand this because it is an public function, and the compiler does not know whether I refer to this method later or not. And, finally, I refer to this method because I call it in main.cpp and despite this compiler's warning, this method works if I compile and link all the files and execute the program : Include

  //main.cpp # & lt; Iostream & gt; #include "Child.h" int main () {child child; Child.Cancel (); // works, despite the warning}  

If I define the cancel () function as an inline (you comment it like code in Absolletles H), then not me Getting Compiler Alert Of course my program works, but I want to understand this warning or is it just a compiler mistake?

In addition, if AbsctractClass is not implemented as a template class (in this case only for a test purpose) I also do not receive compiler warning ...?


If I am creating a non-virtual function, then I have not received a compiled alert for that non-virtual function, but all answers are no longer included in the virtual stuff. Try it out:

  Template & lt; Typename T & gt; Class abstract claus {public: cancel virtual zeros (); // {std :: cout & lt; & Lt; "Cancel Abuse" & lt; & Lt; Std :: endl; }; Virtual Zero Process () = 0; Zero non-virtual function (); }; // ... template & lt; Typename T & gt; Zero Summary & lt; T & gt; :: Non-Virtual Function () {std :: cout & lt; & Lt; "Non-virtual function" & lt; & Lt; Std :: endl; }  

The answer helped me to know, but I do not think the question has been answered completely.

I do not see the right answer anywhere here: if you have a template in a class If there is a pure virtual method, then Visual Studio incorrect reports this warning. Other compilers, such as GCC and Gems, do not appear to report this warning in this situation.

Pure virtual methods are perfectly appropriate in templated or non-templated sections, and often declare a good idea method to implement the pure virtual forces in the derivative classes. it is said.

I did not get a reference anywhere in the form of a bug - I'm not in a Microsoft developer program, maybe someone who can file this bug?


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -