CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Pointer topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 06-14-2010, 07:19 PM
Member
 
Join Date: Feb 2010
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
inspiration is on a distinguished road
| More
Question Pointer

i!

Contributions about pointer to class methods are indeed
already in the forum. Still remain for me what this topic
concern, a few questions unanswered. Would be nice if someone
in answering the following questions might be helpful.

Will ultimately produce for me exactly two of ambiguity:
Problem 1:
----------

I would firstly like to pointer to class methods in a
LinkedList store.
ie:
the Konstruktorenaufruf could look like this:
LinkedList <void (ClassName::*)(void)> list ();

And now the crux:
so I give this call as a template parameter pointer
on methods of class 'Class Name' with the above structure to.

This approach I might now, for example, compared with the Ablau, the
would be required to create a LinkedList for 'ClassName' objects.
also:

a) LinkedList <ClassName *> list ();

A call to like this would be also valid
(I would only adjust the LinkedList internal):

b) LinkedList <ClassName> list ();

And here are my problems!

->
If treatment of the LinkedList, is as done as you b below)
also in the class methods possible?
Is to say:
I may in the call:
LinkedList (ClassName::*)(void)> <void, where I indeed a PointerType
specify, also specify a Klassenmethodentyp?
==> Looks like the syntax for then?

Problem 2:
----------

In various posts in the forum already mentioned that in a
Calling a class method always binding to a specific object is required.
ie:
either as outside of the object like this: (object-> * object-> methodPtr) ();

or within the object like this: (this-> this-*> methodPtr) ();

In this approach, but is always assumed that the methods Pointer
as an attribute of 'object' is present.

What is it but now, if I belong to the object a pointer a
specific class method is present!
How do I call for then the class method?
How do I bind because now the method of the object?

Would be nice if someone could help on the jumps!
Reply With Quote
  #2  
Old 06-14-2010, 07:20 PM
Member
 
Join Date: Feb 2010
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
inspiration is on a distinguished road
| More
Re: Pointer

OK!
Item number two has done it!
Only as far as problem number one, am
I, unfortunately, still no further!

Can someone help me also to this evil
? Eliminate
Reply With Quote
  #3  
Old 06-14-2010, 07:21 PM
Member
 
Join Date: Feb 2010
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
techme is on a distinguished road
| More
Re: Pointer

So std:: list
Code:
# Include <list> 
using namespace std; 

class foo 
( 
public: 
    void f1 () () 
    void f2 () () 
); 

int main () 
( 
    typedef void (foo:: * mem_func_ptr) () / / not necessary but nice 
    list <mem_func_ptr> bla; 
    bla.push_back (& foo:: f1); 
    bla.push_back (& foo:: f2); 

    foo f; 
    for(list <mem_func_ptr>:: iterator i = bla.begin (); i! bla.end = (); + + i) 
        (F * (* i)) () 
)
Reply With Quote
  #4  
Old 06-14-2010, 07:22 PM
Member
 
Join Date: Feb 2010
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
creative is on a distinguished road
| More
Re: Pointer

And if he wants to manage method-pointer coming from other classes as foo?
Reply With Quote
  #5  
Old 06-14-2010, 07:22 PM
Member
 
Join Date: Feb 2010
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
inspiration is on a distinguished road
| More
Re: Pointer

First of all thank you for your answers!

But:
Maybe I am so, what problem number one is concerned,
expressed something unclear.

Syntax of the form:

typedef void (foo:: * mem_func_ptr) ();
list <mem_func_ptr> bla;

or:

list <void (foo::*)()> bla;

I know!

However, I still give as a template parameter
Methods-POINTER type to. I would be interested to know whether it
also be a method type is indicated (no Ptr).
In a normal class it works so well:

<ClassName *> list list () or list <ClassName> list ()

depending on what awaits the LinkedList.
I also see, in the appropriate literature, only the syntax
for method pointers,
So: Return value (class name ::*)( parameters)
but never, for a method type.

Is there such a construct, or perhaps not
is a fallacy in charge?

Please hold on!
Reply With Quote
  #6  
Old 06-14-2010, 07:23 PM
Senior Member
 
Join Date: Feb 2010
Posts: 102
Thanks: 0
Thanked 0 Times in 0 Posts
meyup is on a distinguished road
| More
Re: Pointer

I do not think that would be yes, would you put the function in the list. In C + + functions, but are not objects, they can not copy or delete or something. To that extent, I can not imagine that they could put that species and container.
Reply With Quote
  #7  
Old 06-14-2010, 07:25 PM
Member
 
Join Date: Feb 2010
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
techme is on a distinguished road
| More
Re: Pointer

what you are looking binder
Code:
# Include <list> 
using namespace std; 

class foo 
( 
public: 
    void f1 () () 
    void f2 () () 

    typedef void (foo:: * mem_func_ptr) (); 
); 


class bar 
( 
public: 
    bar (foo * instance, foo:: mem_func_ptr func) 
        : Instanz_ (instance), 
             func_ (func) 
    ( 
    ) 

    void operator() () 
    ( 
        (Insatnz_-> * func_) (); 
    ) 
private: 
    foo * instanz_; 
    foo:: mem_func_ptr func_; 
); 

int main () 
( 

    list <bar> bla; 

    foo a; 
    bla.push_back (bar (& a, & foo:: f1)); 
    
    foo b; 
    bla.push_back (bar (& b, & foo:: f2)); 

    for(list <bar>:: iterator i = bla.begin (); i! bla.end = (); + + i) 
        (I) (); 
)
Reply With Quote
  #8  
Old 06-14-2010, 07:25 PM
Member
 
Join Date: Feb 2010
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
inspiration is on a distinguished road
| More
Re: Pointer

Thank you!
So that I would be happy for the moment.

-> The idea to encapsulate methods and object pointers
and only then can I insert in the LinkedList
good use!

But would certainly also ne good idea, the class 'bar'
to write a template class and then one of these interface
'SuperBar' derived. Then I could even methods and object pointers
any class in 'bar' objects encapsulate and then, as' objects bar'
indeed 'SuperBar' objects are, as' SuperBar' objects in the LinkedList
list <SuperBar> bla insert.
==> Then I could add each item in the list of 'blah' as the command "execute () '
and assign each 'bar' object could be the referenced method
bind to the affected object and execute the method.
We'll see if it's funtzt!

Thank you for your help!
Reply With Quote
  #9  
Old 06-14-2010, 07:26 PM
pankaj.sea's Avatar
Super Moderator
 
Join Date: Sep 2009
Location: Serampore
Posts: 132
Thanks: 0
Thanked 2 Times in 2 Posts
pankaj.sea is on a distinguished road
| More
Re: Pointer

well, that funzt so far, only then it will only work with pointers SuperBar

list <SuperBar*> bla
Reply With Quote
  #10  
Old 06-14-2010, 07:27 PM
Member
 
Join Date: Feb 2010
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
inspiration is on a distinguished road
| More
Re: Pointer

That's right!
For the LinkedList, which I used in my code sample
I have to specify a PtrTyp. Then I did not even care.

But what about if I write the LinkedList itself. As my
own list of template parameters interpreted certain Whether an object or
Ptrtyp, I can not control, is not it?

I think then the syntax should be correct!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer and Class inspiration C++ Programming 8 05-31-2010 08:55 PM
array and pointer mmondal71 C Programming 1 05-31-2010 01:50 AM
Help on pointer techinspiration C++ Programming 0 05-30-2010 08:55 PM
Pointer problem techinspiration C Programming 1 05-21-2010 02:17 AM
gcc and pointer-to-arrays Alex C Programming 0 04-12-2009 07:33 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 01:51 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board