473,405 Members | 2,404 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,405 software developers and data experts.

Calling a Template member function without specifying a type

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 -
t

Jul 22 '05 #1
3 1360

"ogtindeed" <og*******@yahoo.com> wrote in message
news:3c**************************@posting.google.c om...
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
Jul 22 '05 #2
On 10 Feb 2004 02:03:29 -0800, og*******@yahoo.com (ogtindeed) wrote:
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<typename foo1 = char>
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
Jul 22 '05 #3

"tom_usenet" <to********@hotmail.com> wrote in message
news:qe********************************@4ax.com...
| On 10 Feb 2004 02:03:29 -0800, og*******@yahoo.com (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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Espen Ruud Schultz | last post by:
I have a template with some common functions: template< class Type > class Object : public Type { public: void Function( void ); };
10
by: jim.brown | last post by:
Please refer me to the right place if this is the wrong place to post this question. I'm looking for an example of calling the Eigenvalue routines of JAMA from a C++ program. The documentation...
13
by: john.constantine | last post by:
Hi I have this code: template<typename ClassType> struct S { template<typename FunctionType> void member() {}; };
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...
16
by: PengYu.UT | last post by:
Hi, I want to partial specialize the member function doit. But it doesn't work. Could you please help me to figure out what is wrong? Thanks, Peng template <typename T> class A {
3
by: gary.bernstein | last post by:
I want to call a singleton getInstance function to retrieve a templatized object without knowing what types were used to create the singleton object in the first call to getInstance. How can I do...
5
by: Jeff Newman | last post by:
Hi all, I am trying to figure out what is causing the compile error in the following example. I have two functions which are identical (except one is templated), both trying to call a template...
6
by: Ole Nielsby | last post by:
VC has a __cdecl specifier which allows functions and methods to be called with varying parameter count. (I understand this is the default for functions in general but in VC, instances use...
2
by: unauthorized | last post by:
The short story: I need to be able to cast a function pointer for any function and class to an intermediate type, so I could call it from any point of my program using the "__asm call" instruction....
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.