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

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.

Comments
Well said!
good advice

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:

Edited 6 Years Ago by Fbody: n/a

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

This article has been dead for over six months. Start a new discussion instead.