Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about objects

Status
Not open for further replies.

darkrunic

Programmer
Oct 16, 2003
4
US
Hi there,

I have a somewhat strange question about using custom objects. I have an external array to which I'd like to add an object that I'm currently working in (in a member function). I'd like to be able to add 'this' object to said array from within the member function, but I can't find out how (or if its even possible). So, to summarize, I want to hand a whole instance of a class to an external array from within that class's member function. Is this possible? Thanks!

Brian
 
Something like this?

Code:
#include <vector>

class SomeClass;
typedef std::vector<SomeClass*> SomeArray;
class SomeClass
{
   ..
   void addMe(SomeArray& a)
   {
     a.push_back(this)
   }
   ...
};

/Per
[sub]
&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;[/sub]
 
Yes, that's exactly what I mean. Only problem is, just using 'this' didn't work :(
 
State what error you get. Be specific.

/Per
[sub]
&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top