By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,417 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,417 IT Pros & Developers. It's quick & easy.

template type

P: n/a
template<class Type>
struct signal
{
int num;
Type* pData;
};
//--------method--------
template<class Type>
signal<Type>* createSignal(const int num){

signal<Type>* pSignal = new signal<Type>;

pSignal->num = num;
pSignal->pData = new Type[num];

return pSignal;
}

It does not compile, why? how to fix it?

Thanks,

goor

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
au******@yahoo.com wrote:
template<class Type>
struct signal
{
int num;
Type* pData;
};
//--------method--------
Method means a member function or sometimes a virtual member function. The
following is a non-memebr function.
template<class Type>
signal<Type>* createSignal(const int num){

signal<Type>* pSignal = new signal<Type>;

pSignal->num = num;
pSignal->pData = new Type[num];

return pSignal;
}

It does not compile, why? how to fix it?
What error are you getting? What compiler, including version?
Thanks,

goor


Jonathan
Jul 23 '05 #2

P: n/a

au******@yahoo.com wrote:
template<class Type>
struct signal
{
int num;
Type* pData;
};
//--------method--------
template<class Type>
signal<Type>* createSignal(const int num){

signal<Type>* pSignal = new signal<Type>;

pSignal->num = num;
pSignal->pData = new Type[num];

return pSignal;
}

It does not compile, why? how to fix it?

Thanks,

goor


There could be any number of reasons. You did not post the complete
code that reproduces your problem. One possible reason I can think of
is that 'Type' does not have a default ctor. Of course, we wouldn't
know until you tell us what 'Type' you are compiling with?

Hope this helps,
-shez-

Jul 23 '05 #3

P: n/a
It works on my compiler.

maybe -
int main(int argc, char** argv)
{
signal<int>* psig = createSignal(1);
}

will give an error because the compiler cannot deduce the type of 'Type' in
Signal<Type>,
but:
int main(int argc, char** argv)
{
signal<int>* psig = createSignal<int>(1);
}

(for example) is fine. I think this is down to ADL (argument dependant
lookup) but happy to be corrected.

regards,
Aiden
<au******@yahoo.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
template<class Type>
struct signal
{
int num;
Type* pData;
};
//--------method--------
template<class Type>
signal<Type>* createSignal(const int num){

signal<Type>* pSignal = new signal<Type>;

pSignal->num = num;
pSignal->pData = new Type[num];

return pSignal;
}

It does not compile, why? how to fix it?

Thanks,

goor


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.