you need to have the concept of 'object oriented programing' . A behavior(function) is belong to a object, it can not exist seprately. just like a hand can not do anything if it is not a part of a body....
Thinking in this way you 'll get the idea.
if you still want to use it in traditional way, you can not declare the function in a class.
Not quite.
You can have behavior functions via the 2nd and 3rd levels of polymorphism also.
The 3 (or maybe '4') levels of Polymorphism that I know of are-
1.) Virtual
2.) Static
3.) Callback
[4.) Delegation]
- the 4th is questionable since I've only recently heard about it and it seems to be an implementation in only a select few languages @_@.
You can have a Callback method that uses polymorphism via calling some function that meets the required signature (return, parameters, and class/nonclass info, and any other info regarding if the method is meant for const and non-const objects or just non-const objects... possibly even calling convention... possibly even the restriction of the scope of the function (though I don't think I've encountered that issue), etc). Of course the method may not have the same name as another but it will have enough similar traits to be invoked as a generalized type at run-time.
There's also Static polymorphism. This is typical with template-types where method and member lookup for an object is resolved at compile time. I'm still a bit fuzzy on this topic, but from what I understand you can use any class as a template argument for a class so long as it meets the minimum requirements of operations used on the template. For example, if the generalized-type is constructed anywhere as a temporary reference for the execution of a method, the class argument that is standing in place of the templated type must have its default constructor defined... etc.
Delegation is a topic I can't explain >_<. You'd have to look it up, and potentially experiment with it to understand it @_@.
So in a nutshell you can have multiple objects with the same behavior functions without using the virtual mechanism, but instead either the static mechanism (which is popular in C++), or the traditional callback mechanism (which was the solution for C-based polymorphism).
@JustLearning
To save us some document-sifting, can you be more elaborate as to what type of error you're getting? What does it say when you try to compile?