• Create Account

### #ActualServant of the Lord

Posted 27 December 2012 - 11:33 PM

As far as I can see, you didn't actually post your error message.

As far as I can guess, your error is telling you that your template isn't correct. Here's your template:

template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}

As far as I can throw an exception (Poor attempt at humor. It's late), here's what I think is wrong:

First, you return a type of 'Entity'. I think you meant, EntityType.

Second, 'new' creates a dynamic class of type 'Type', right? So 'new int' creates a new int. You can't do 'new 5', even though '5' is an instance of an int.

Your function doesn't create a new EntityType (a class type), it's trying to create a new instance of EntityType.

This is incorrect:

int myInt = 5;
new myInt;
//Or:
EntityType type;
new type;

This is correct:

new int;
//Or:
new EntityType;

Thus, this:

template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}

Should be this:

template<class EnityType>
EnityType* EnityFactory:: InstantiateEnity(EnityType type)
{
return new EnityType;
}

And since you aren't using the parameter at all, you might as well remove it:

template<class EnityType>
EnityType* EnityFactory:: InstantiateEnity()
{
return new EnityType;
}
I didn't explain that too well, but did you understand what I mean? You can't 'new' an instance of a type, you can only new a type itself.

Edit: Now I see your error message!

Using the corrected code I show above, the correct way to call such a function would be:
Entity *myEntity = eFactory.InstantiateEnity<Entity>();

By the way, the definition of your entire templated function must be in the header file, as ugly as that is. It's a shortcoming of templates. Any function that is templated must be entirely (declaration and definition) in the header.

### #3Servant of the Lord

Posted 27 December 2012 - 11:29 PM

As far as I can see, you didn't actually post your error message.

As far as I can guess, your error is telling you that your template isn't correct. Here's your template:

template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}

As far as I can throw an exception (Poor attempt at humor. It's late), here's what I think is wrong:

First, you return a type of 'Entity'. I think you meant, EntityType.

Second, 'new' creates a dynamic class of type 'Type', right? So 'new int' creates a new int. You can't do 'new 5', even though '5' is an instance of an int.

Your function doesn't create a new EntityType (a class type), it's trying to create a new instance of EntityType.

This is incorrect:

int myInt = 5;
new myInt;
//Or:
EntityType type;
new type;

This is correct:

new int;
//Or:
new EntityType;

Thus, this:

template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}

Should be this:

template<class EnityType>
EnityType* EnityFactory:: InstantiateEnity(EnityType type)
{
return new EnityType;
}

And since you aren't using the parameter at all, you might as well remove it:

template<class EnityType>
EnityType* EnityFactory:: InstantiateEnity()
{
return new EnityType;
}
I didn't explain that too well, but did you understand what I mean? You can't 'new' an instance of a type, you can only new a type itself.

### #2Servant of the Lord

Posted 27 December 2012 - 11:28 PM

As far as I can see, you didn't actually post your error message.

As far as I can guess, your error is telling you that your template isn't correct. Here's your template:

template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}

As far as I can throw an exception, here's what I think is wrong:

First, you return a type of 'Entity'. I think you meant, EntityType.

Second, 'new' creates a dynamic class of type 'Type', right? So 'new int' creates a new int. You can't do 'new 5', even though '5' is an instance of an int.

Your function doesn't create a new EntityType (a class type), it's trying to create a new instance of EntityType.

This is incorrect:

int myInt = 5;
new myInt;
//Or:
EntityType type;
new type;

This is correct:

new int;
//Or:
new EntityType;

Thus, this:

template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}

Should be this:

template<class EnityType>
EnityType* EnityFactory:: InstantiateEnity(EnityType type)
{
return new EnityType;
}

And since you aren't using the parameter at all, you might as well remove it:

template<class EnityType>
EnityType* EnityFactory:: InstantiateEnity()
{
return new EnityType;
}
I didn't explain that too well, but did you understand what I mean? You can't 'new' an instance of a type, you can only new a type itself.

### #1Servant of the Lord

Posted 27 December 2012 - 11:26 PM

As far as I can see, you didn't actually post your error message.

As far as I can guess, your error is telling you that your template isn't correct:

template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}

First, you return a type of 'Entity'. I think you meant, EntityType.

Second, 'new' creates a dynamic class of type 'Type', right?

So 'new int' creates a new int. You can't do 'new 5', even though '5' is an instance of an int.

Your function doesn't create a new EntityType (a class type), it's trying to create a new instance of EntityType.

This is incorrect:

int myInt = 5;
new myInt;
//Or:
EntityType type;
new type;

This is correct:

new int;
//Or:
new EntityType;

Thus, this:

template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}

Should be this:

template<class EnityType>
EnityType* EnityFactory:: InstantiateEnity(EnityType type)
{
return new EnityType;
}

And since you aren't using the parameter at all, you might as well remove it:

template<class EnityType>
EnityType* EnityFactory:: InstantiateEnity()
{
return new EnityType;
}

I didn't explain that too well, but did you understand what I mean? You can't 'new' an instance of a type, you can only new a type itself.

PARTNERS