Re: [RESOLVED] template for events
Quote:
Originally Posted by
D_Drmmr
what you can tell me about static class members?
but i only see examples with class's names and not with objects\instances names... but what you can tell me?
Re: [RESOLVED] template for events
Quote:
Originally Posted by
Cambalinho
what you can tell me about static class members?
but i only see examples with class's names and not with objects\instances names... but what you can tell me?
The only useful thing I can tell you, is that there probably is a good design for what you are trying to do in C++. But as long as you refuse to share what it is you are trying to do and are merely stuck on the solution that you would have chosen in another programming language, I can't help you any further.
Re: [RESOLVED] template for events
Quote:
Originally Posted by
D_Drmmr
The only useful thing I can tell you, is that there probably is a good design for what you are trying to do in C++. But as long as you refuse to share what it is you are trying to do and are merely stuck on the solution that you would have chosen in another programming language, I can't help you any further.
ok..thanks for all
at least doing that template was great, wasn't?
Re: [RESOLVED] template for events
see the actual template:
Code:
template <class ... b>
class events
{
public:
typedef std::function<void(b...argx )> OnSomethingHandler;
events(OnSomethingHandler Handler)
{
handlers_=Handler;
}
void operator() (b&&... args)
{
handlers_ (std::forward<b> (args)...);
}
events& operator = (OnSomethingHandler Handler)
{
handlers_ = Handler;
return *this;
}
private:
OnSomethingHandler handlers_;
};
i'm trying convert it for a class, but i'm gettings errors because of parameters:
Code:
class events2
{
public:
typedef std::function<void(...)> OnSomethingHandler;
events2(OnSomethingHandler Handler)
{
handlers_=Handler;
}
void operator() (...)
{
handlers_ (...);
}
events2& operator = (OnSomethingHandler Handler)
{
handlers_ = Handler;
return *this;
}
private:
OnSomethingHandler handlers_;
};
error:
"C:\Users\Joaquim\Documents\CodeBlocks\My Class\events.h|56|error: field 'handlers_' has incomplete type|"
can anyone advice me?
Re: [RESOLVED] template for events
Quote:
Originally Posted by
Cambalinho
ok..thanks for all
at least doing that template was great, wasn't?
Just because you attempted to use templates doesn't mean it is a good idea or good design.
Regards,
Paul McKenzie
Re: [RESOLVED] template for events
yah... that's why i'm trying convert it to a class
Re: [RESOLVED] template for events
Quote:
Originally Posted by
Cambalinho
yah... that's why i'm trying convert it to a class
How does that help? When I talk about design, I just don't mean syntax.
What is it that you're trying to accomplish? Don't talk about templates or classes -- tell us what you're trying to do on a high level.
Regards,
Paul McKenzie
Re: [RESOLVED] template for events
Quote:
Originally Posted by
Paul McKenzie
How does that help? When I talk about design, I just don't mean syntax.
What is it that you're trying to accomplish? Don't talk about templates or classes -- tell us what you're trying to do on a high level.
Regards,
Paul McKenzie
declare events: event created(); or event position(int x, int y);
and then change them:
Code:
void created()
{
cout << "hello world";
}
void position(int x, int y)
{
if (x==100) cout << "position 100";
if (y==1000) cout << "position 1000";
}
is what i need with that class
Re: [RESOLVED] template for events
But your're still talking at the code level - not at the high design level. Without using one line of code or any c++ terminology, explain what you are trying to accomplish.
Re: [RESOLVED] template for events
Quote:
Originally Posted by
2kaud
But your're still talking at the code level - not at the high design level. Without using one line of code or any c++ terminology, explain what you are trying to accomplish.
1st i need declare 1 function variable, but that variable must accept parameters or not. how can i do it?
typedef std::function<void(...)> OnSomethingHandler;
Re: [RESOLVED] template for events
Quote:
Originally Posted by
Cambalinho
1st i need declare 1 function variable,
You're still talking on the code level.
Pretend the language is not relevant (C++, Java, C#, etc.). You are talking to us and you don't know what computer language we use, but we do know object-oriented analysis and design. What are you trying to accomplish? What design pattern, algorithm, paradigm are you trying to implement?
Quote:
Originally Posted by
Cambalinho
1st i need declare 1 function variable,
Let's start right there. Why do you "need" to declare such a function? That's the issue that we have with your posts and code. We claim there is no "need" to do most of what you're doing -- the problem is that we can't give you workable solutions until we find out what you're trying to do.
Remember the thread you started a few weeks ago?
http://forums.codeguru.com/showthrea...-function-name
Compare your "solution" to the one that others and myself gave. Our solution was only given once we understood what you were trying to do on a high-level.
The solutions given to you in that thread were derived from first analyzing the problem at a high level, and then incorporating known and well-tested paradigms from C++ to implement the solution. We didn't just take C++ syntax we saw on a website and fight with it until it "fits" with what we want.
For example, we expect you to say something like this:
"I am attempting to design an event handler, where the event handler calls out to several different functions when an event occurs".
Note that the description doesn't use a single word about classes, templates, void functions with varying arguments, etc. It describes the problem on a high-level and now would make us understand what it is you're doing. If you're going down the correct path of implementing such a thing, then we will say so and give you advice. If not, then we will say why it is the wrong path and give you alternatives (just like the previous thread that I mentioned).
So please formulate a non-C++ description, similar to the one I wrote above, as to what you're trying to do. Once you do that, then you will get more help on this forum.
Regards,
Paul McKenzie
Re: [RESOLVED] template for events
Quote:
Originally Posted by
Paul McKenzie
You're still talking on the code level.
Pretend the language is not relevant (C++, Java, C#, etc.). You are talking to us and you don't know what computer language we use, but we do know object-oriented analysis and design. What are you trying to accomplish? What design pattern, algorithm, paradigm are you trying to implement?
Let's start right there. Why do you "need" to declare such a function? That's the issue that we have with your posts and code. We claim there is no "need" to do most of what you're doing -- the problem is that we can't give you workable solutions until we find out what you're trying to do.
Remember the thread you started a few weeks ago?
http://forums.codeguru.com/showthrea...-function-name
Compare your "solution" to the one that others and myself gave.
Our solution was only given once we understood what you were trying to do on a high-level.
The solutions given to you in that thread were derived from first analyzing the problem at a high level, and then incorporating known and well-tested paradigms from C++ to implement the solution. We didn't take C++ syntax and fight with it until it fits our ideas (as what you're doing now).
Regards,
Paul McKenzie
i need 1 object that can change the function(it's value) and call that function. these function can recive arguments or not
Re: [RESOLVED] template for events
Quote:
Originally Posted by
Cambalinho
i need 1 object that can change the function(it's value)
Explain what you mean by "change the function's value". That is not clear.
Regards,
Paul McKenzie
Re: [RESOLVED] template for events
Quote:
Originally Posted by
Paul McKenzie
Explain what you mean by "change the function's value". That is not clear.
Regards,
Paul McKenzie
events a();
a={ cout << "hello world";};
(in other place we can change what a do)
Re: [RESOLVED] template for events
You're back to using c++ synatx again in your explanation. Why do you want to do this? At a higher design level, what are trying to achieve? We don't understand your design ojectives which is why we're having trouble helping you.