is possible do a instance polymorphism?
i understand that i can create class's with virtual functions, but i only can change them with another class and not with objects\instances
is possible do a instance polymorphism?
i understand that i can create class's with virtual functions, but i only can change them with another class and not with objects\instances
I am not sure if you mean prototype based inheritance or monkey patching, but as far as I know, neither is (normally) possible in standard C++.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
sorry to both... think in these way:
these is the class polymorphism.(code not tested)Code:#include <iostream> using namespace std; class test { public: virtual void print(){}; }; class test1 : test { public: void print(); }; void test1::print() { cout << "hello world"; }
(sorry, if i'm mistake in something, please tell... i'm 'new' with some concepts)
now see these 2 example:
i don't know if you understand what i mean... but i'm tryingCode:#include <iostream> using namespace std; class test { public: virtual void print(){}; }; test a, b; void a::print() { cout << "hello world\n"; } void b::print() { cout << "hello C Board Programing\n"; } int main() { a.print(); b.print(); cin.get(); }
(i'm portuguese)
Last edited by joaquim; 02-01-2014 at 12:35 PM.
Can't be done.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The effect that you have in mind can be done in standard C++, e.g., by assigning a unique id to each object and then selecting the behaviour based on this id. Why do you want to do this? Perhaps a better way can be suggested.Originally Posted by joaquim
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
sorry, i mean:
Code:#define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname
I don't know what you mean by "build events" and I don't know exactly what you are trying to change and where. Logically though, if you have a callback function (object), you can replace it at run time.Originally Posted by joaquim
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
sorry my english
but what i realy need is these:
returntype objectname::functionname()//with arguments or not
but doing outside of the main function...
sorry but i'm problems to express better but i think the MFC way, can give you a clue... i think. or the Visual C++ form applications.
they use the '::' operator for change\write the event(the windows messages are events)
That sounds simple enough: returntype would be your callback function (object) type. functionname, which probably should be renamed to something more descriptive, would just return the callback function (object). You can then set the function (object) on a per-object basis outside of the main function, at run time, and then retrieve it from the object named obj by calling obj.functionname(). I don't see a problem.Originally Posted by joaquim
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Oh right, by objectname you really mean an object's name, not a class named objectname.Originally Posted by joaquim
I am not familiar with MFC or Visual C++ form applications, but here's the thing: why does it matter that in the interface that they provide, the scope resolution operator (i.e., :: ) is used? That's just syntax; it only matters in the bigger picture of the interfaces that they provide. What's more important is what you are trying to do. So if you say that:Originally Posted by joaquim
then I can tell you that since what you really need is invalid C++, you need to change what you really need, or perhaps recognise that you didn't really need it to begin with. If you cannot do that, then you need to change programming language, or change the programming language.Code:but what i realy need is these: returntype objectname::functionname()//with arguments or not
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
what i know that i can do these:
it's very nice... true, but i must use 'a.print=&hello;'... unless we can do:Code:#define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname class test { public: event(Print)=[](){;}; }; void hello() { cout << "hello world"; } int main() { test a; a.print=&hello; a.print(); return 0; }
what you can tell me about my thot?Code:#define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname class test { public: event(Print)=[](){;}; }; void a_hello() { cout << "hello world"; } int main() { test a; a.print=&hello;//and the compiler do these line...(it's just a thot) a.print(); return 0; }
(sorry if i bored you with these thread, but i want something like these)