Calling a Template member function without specifying a type

O

ogtindeed

Hi all,

I need some help. I am trying to instantiate a Template and call a
member function, but have not been able -

Now this is what I am trying to do:

foo.h
=========

template<typename foo1>
class myClass
{
public:
void display(foo1);
};


template <typename foo1>
void myClass<foo1>::display(foo1 outdata)
{
cout<<outdata<<"\n";
}

foo.cpp
========

int main(int argc, char* argv[])
{
myClass mc; // compiler complains here-Is there anyway around
this?
myClass<char> mc; //compiler accepts this-But I don't want this?
return (0);
}


Many thanks for the help. I appreciate -
 
J

Jonathan Turkanis

ogtindeed said:
Hi all,

I need some help. I am trying to instantiate a Template and call a
member function, but have not been able -

Now this is what I am trying to do:

foo.h
=========

template<typename foo1>
class myClass
{
public:
void display(foo1);
};


template <typename foo1>
void myClass<foo1>::display(foo1 outdata)
{
cout<<outdata<<"\n";
}

foo.cpp
========

int main(int argc, char* argv[])
{
myClass mc; // compiler complains here-Is there anyway around
this?

Nope. Class template arguments are never deduced. Even if they were,
you haven't given the compiler any clues as to what the template
arguments should be. What are you trying to achieve?

Jonathan
 
T

tom_usenet

Hi all,

I need some help. I am trying to instantiate a Template and call a
member function, but have not been able -

Now this is what I am trying to do:

foo.h
=========

You can default template parameters:

template said:
class myClass
{
public:
void display(foo1);
};
int main(int argc, char* argv[])
{
myClass mc; // compiler complains here-Is there anyway around
this?
myClass<char> mc; //compiler accepts this-But I don't want this?
return (0);
}

I can only assume you want defaults. Or perhaps you just need a
non-template? Or a member template? More detail is required...

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 
C

Chris \( Val \)

| On 10 Feb 2004 02:03:29 -0800, (e-mail address removed) (ogtindeed) wrote:

[snip]

Hi Tom.

| >I need some help. I am trying to instantiate a Template and call a
| >member function, but have not been able -
| >
| >Now this is what I am trying to do:
| >
| >foo.h
| >=========
| >
|
| You can default template parameters:
|
| template<typename foo1 = char>

But that would require that you declare the following as such:

myClass<> mc;

| > myClass mc; // compiler complains here-Is
// there anyway around this?

[snip]

Which doesn't really do what the OP wanted.

I think you're right though, the OP really
needs to be more specific in what s/he requires.

Cheers.
Chris Val
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top