public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* typedef and pass variable
@ 2012-07-09  7:27 Mohsen Pahlevanzadeh
  2012-07-09  8:03 ` Mohsen Pahlevanzadeh
  0 siblings, 1 reply; 4+ messages in thread
From: Mohsen Pahlevanzadeh @ 2012-07-09  7:27 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 575 bytes --]

Dear all,
Suppose i have a func such as a following func:
////////////////////
template <class T>
Class *makeInstance(T *_class,Method _method,Class* _instance_class,ReturnType _returnType,Parameter1 parameter1,Parameter2 parameter2, Parameter3 parameter3, Parameter4 parameter4){
typedef MyCLass< &_class, ReturnType, Parameter1, Parameter2, Parameter3, Parameter4>  cbd;
};
/////////////////////////
In typedef line, i must pass class name as argumnent , how i do it?
When i put a real class name instead of _class my error is solved.

--Best Regards
Mohsen


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 316 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: typedef and pass variable
  2012-07-09  7:27 typedef and pass variable Mohsen Pahlevanzadeh
@ 2012-07-09  8:03 ` Mohsen Pahlevanzadeh
  2012-07-09  8:13   ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Mohsen Pahlevanzadeh @ 2012-07-09  8:03 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1580 bytes --]

I changed the given func to the :
///////////////////////////////////
template <class T,class MyCLass>
Class *makeInstance(T *_class,Method _method,Class* _instance_class,ReturnType _returnType,Parameter1 parameter1,Parameter2 parameter2, Parameter3 parameter3, Parameter4 parameter4){
typedef (&_class) __class ;
typedef MyCLass<__class, ReturnType, Parameter1, Parameter2, Parameter3, Parameter4>  callback;
__class cptr(1);
callback cptr(&_instance_class, &_method);
};
/////////////////////////////////////
and get the following errors:
//////////////////////////////////
49:24: error: expected initializer before ‘__class’
50:14: error: ‘EventHandlerAbstract’ is not a template
50:35: error: ‘__class’ was not declared in this scope
51:14: error: expected ‘;’ before ‘cptr’
//////////////////////////////////
Seriously  i stay to pass variable to typedef...
--mohsen
On Mon, 2012-07-09 at 11:57 +0430, Mohsen Pahlevanzadeh wrote:
> Dear all,
> Suppose i have a func such as a following func:
> ////////////////////
> template <class T>
> Class *makeInstance(T *_class,Method _method,Class* _instance_class,ReturnType _returnType,Parameter1 parameter1,Parameter2 parameter2, Parameter3 parameter3, Parameter4 parameter4){
> typedef MyCLass< &_class, ReturnType, Parameter1, Parameter2, Parameter3, Parameter4>  cbd;
> };
> /////////////////////////
> In typedef line, i must pass class name as argumnent , how i do it?
> When i put a real class name instead of _class my error is solved.
> 
> --Best Regards
> Mohsen
> 


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 316 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: typedef and pass variable
  2012-07-09  8:03 ` Mohsen Pahlevanzadeh
@ 2012-07-09  8:13   ` Jonathan Wakely
  2012-07-09 12:22     ` Mohsen Pahlevanzadeh
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2012-07-09  8:13 UTC (permalink / raw)
  To: Mohsen Pahlevanzadeh; +Cc: gcc-help

On 9 July 2012 09:03, Mohsen Pahlevanzadeh wrote:
> I changed the given func to the :
> ///////////////////////////////////
> template <class T,class MyCLass>
> Class *makeInstance(T *_class,Method _method,Class* _instance_class,ReturnType _returnType,Parameter1 parameter1,Parameter2 parameter2, Parameter3 parameter3, Parameter4 parameter4){
> typedef (&_class) __class ;

1) __class is not a legal name, do not use names containing a double
underscore, or names beginning with underscore followed by uppercase
letter, they are reserved for the implementation.

2) &_class has type T**, i.e. it is the address of a pointer, it's not
a type, let alone a class type.

Surely the type you want is named by one (or both) of the template
parameters T and Class.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: typedef and pass variable
  2012-07-09  8:13   ` Jonathan Wakely
@ 2012-07-09 12:22     ` Mohsen Pahlevanzadeh
  0 siblings, 0 replies; 4+ messages in thread
From: Mohsen Pahlevanzadeh @ 2012-07-09 12:22 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 3018 bytes --]

Dear Janathan and others,
I changed my func to :
//////////////////////////////
template <class T>
static Class *makeInstance(T *_class,string _event,Method _method,Class* _instance_class,ReturnType _returnType,Parameter1 parameter1 = 0,Parameter2 parameter2 = 0, Parameter3 parameter3 = 0, Parameter4 parameter4 = 0)
{
typedef typeof(_class) _Class ;
typedef EventHandlerAbstract<_Class, ReturnType, Parameter1, Parameter2, Parameter3, Parameter4>  _callback;
_Class _instance(1);
_callback classPointer(&_instance, &_method);
EventHandlerAbstract::callback_list.push_back(std::pair< int ,void* >( EventHandlerAbstract::callback_list.size()+1 , static_cast<void*>(&_instance)));
EventHandlerAbstract::event_list.push_back(std::pair< int ,void* >( EventHandlerAbstract::event_list.size()+1 , &_event ));
return _instance_class;
//////////////////////////////////
EventHandlerAbstract is same Myclass, It's so compiled, But when i
called it such as following:
//////////////////////////////////////////////////////////////
test ptr = test();
EventHandlerAbstract<ptr,int,int,int,int,int>::makeInstance(test,(string)"call",test::caller(),&ptr,bool);
////////////////////////////////////////////////////////////////
I get the following errors:
//////////////////////////////////////////////////////////////////
main.cpp:15:25: error: ‘ptr’ cannot appear in a constant-expression
main.cpp:15:48: error: template argument 1 is invalid
main.cpp:15:69: error: expected identifier before ‘(’ token
main.cpp:15:77: error: expected ‘,’ or ‘...’ before string constant
main.cpp:15:109: error: invalid type in declaration before ‘;’ token
////////////////////////////////////////////////////////////////
By the way, I define my class with the following template:
///////////////////////////////////////////////////////////
template < class Class, typename ReturnType,typename Parameter1 = void ,
typename Parameter2 = void, typename Parameter3 = void, typename
Parameter4 = void >
class EventHandlerAbstract
{... }
////////////////////////////////////////////////////
Thank you so for much.....
--mohsen
On Mon, 2012-07-09 at 09:13 +0100, Jonathan Wakely wrote:
> On 9 July 2012 09:03, Mohsen Pahlevanzadeh wrote:
> > I changed the given func to the :
> > ///////////////////////////////////
> > template <class T,class MyCLass>
> > Class *makeInstance(T *_class,Method _method,Class* _instance_class,ReturnType _returnType,Parameter1 parameter1,Parameter2 parameter2, Parameter3 parameter3, Parameter4 parameter4){
> > typedef (&_class) __class ;
> 
> 1) __class is not a legal name, do not use names containing a double
> underscore, or names beginning with underscore followed by uppercase
> letter, they are reserved for the implementation.
> 
> 2) &_class has type T**, i.e. it is the address of a pointer, it's not
> a type, let alone a class type.
> 
> Surely the type you want is named by one (or both) of the template
> parameters T and Class.


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 316 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-09 12:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-09  7:27 typedef and pass variable Mohsen Pahlevanzadeh
2012-07-09  8:03 ` Mohsen Pahlevanzadeh
2012-07-09  8:13   ` Jonathan Wakely
2012-07-09 12:22     ` Mohsen Pahlevanzadeh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).