hey guys, i need to pass 'this' as the template function parameter..
any help will be appreciated.

can you provide some code?? It's easier for me to understand that way.

hey guys, i need to pass 'this' as the template function parameter..
any help will be appreciated.

Where is the function?

You'll have to explain this better, and provide some code. What you are talking about is generally not advisable.

If you've designed your system correctly, you really shouldn't have to pass "this" to something. I think you need to take a closer look at your design.

commented: good advice +34
commented: Well said! +6

thanks everyone, but i solved it already..

anyways here's an example:

class a
{
public:
	a()
	{
		num = 0;
	};
	~a()
	{

	};
	int func()
	{
		return getnum(this);
	}

	template <class inp>
	int getnum(const inp & _inp)
	{
		return _inp->num;
	}
private:
	int num;
};

:confused: Why on earth would you do that? That's a lot of screwing around to just return a value you already have access to:confused:

class a
{
public:
  a()
  {
    num = 0;
  };
  ~a()
  {
  };

  /* original code...
  int func()
  {
    return getnum(this);
  }
 
  template <class inp>
  int getnum(const inp & _inp)
  {
    return _inp->num;
  }  */

  //new code
  int func()
  {
    return this->num;
  }

private:
  int num;
};

:confused::confused::confused:

yeah i know! but this is just an example..
im actually making a gui library, so like inside the window class i can call the function CreateWindow and pass 'this' as its parent window..
it is something like this:

window win1;
win1.CreateWindow(this, 10, 10);
//inside window class
template <class Widget>
void CreateWindow(const Widget & parent, const int x, const int y)
{
    // create window using parent->Handle() as its parent window handle..
}

I was wondering if this was some sort of GUI thing. All the rules go out the window with GUIs. That's why I don't do them (yet).

I think you need to look at your design again. For some reason what you are doing doesn't seem like a good way to go about it. I would suggest an alternative but, I'm not completely sure how your code works.

Fbody - hahah yeah i know

firstPerson - no i think its fine, but im gona use the other method though, cause sometimes the window might have no parent, and so passing 0 (or NULL) won't work..
so i will just pass this->Handle()
and the CreateWindow function will have the first parameter as HWND

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.