Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 05 Aug 2012
Offline Last Active Aug 23 2013 12:45 PM

Topics I've Started

decltype template parameter

21 June 2013 - 04:38 PM

Hi, I seem to having a little trouble with something that is seemingly simple.

I would like to get a typedef from my own traits class where the template is instantiated based on a member T::member.

It would be easier to just show an example of what I'm talking about

template <typename T> class someclass
	// doesnt work
	typedef ns::some_traits<decltype(T::member)>::type type;

// works
typedef ns::some_traits<decltype(otherclass::member)>::type type;

To me this looks like I'm missing a typename somewhere in there but I've tried that in a number of variations.

Could it be a compiler bug (which I doubt)? I'm using the Visual C++ November 2012 CTP compiler.  If not what is the problem here?


Thanks in advance.

c++ delegates, evil method?

14 April 2013 - 12:51 AM

Hello all, been a while, I'm working on this project for a university assignment and I would really like

delegates in C++ haha, so I came up with something in a side test project and I'm pretty sure its

evil, could someone explain to me what could happen if it is in fact evil (ignoring the usual errors that could happen)


It compiles and runs correctly in visual studio 2012 without warnings

heres the code:


#include <iostream>
#include <list>

class object 

struct eventargs { };

template <typename eventargs_t> struct delegate {
	typedef void (object::*type)(object*, eventargs_t*);

typedef delegate<eventargs>::type			eventhandler;

template <typename handler_t>
class event
	std::list<handler_t>	_handlers;

	template <typename handler_u> // I would like to see if the handler_u class is derived from 'object'
	void addhandler(handler_u handler) { _handlers.push_back((handler_t)handler); }

	template <typename handler_u> // I would like to see if the handler_u class is derived from 'object'
	void removehandler(handler_u handler) { _handlers.remove((handler_t)handler); }

	void invoke(object* sender, eventargs* args)
		std::list<handler_t>::iterator it;
		for (it = _handlers.begin( ); it != _handlers.end( ); ++it)
			(sender->*(*it))(sender, args);

class other : public object
	void myhandler(object* sender, eventargs* args) { std::cout << "Hello World!" << std::endl; }
	void myhandler2(object* sender, eventargs* args) { std::cout << "Goodbye World!" << std::endl; }

int main(int, char**)
	object *a = new other( );
	event<eventhandler> e;

	e.invoke(a, nullptr);

	e.invoke(a, nullptr);

	return 0;


... Pretty sure its evil, but in what way?...

Just FYI I'm probably going to remove the templated parts of add/removehandler