473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

template type

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
3 1595
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nobody | last post by:
This is sort of my first attempt at writing a template container class, just wanted some feedback if everything looks kosher or if there can be any improvements. This is a template class for a...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
3
by: case2005 | last post by:
Can anyone help with the following, I don't know if it's possible, but I'm certain there must be a standard way of dealing with this. I have the following: template<typename FooBar, typename...
6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
5
by: Axter | last post by:
I'm fine tuning a scope_handle class that takes a policy class as the second template. http://code.axter.com/scope_handle.h Please see above link for full understanding of the problem. One...
1
by: mathieu | last post by:
Hello there, I am playing around with template metaprograming: I am trying to redefines my own types. But I am facing a small issue, where I cannot describe the whole implementation in one...
19
by: aaragon | last post by:
Hi everyone. A very simple question. I would like to know what is better in terms of performance. I want to use a simple function to obtain the minimum of two values. One way could be using a...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
2
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.