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

Whether a Template function is possible in a normal class

21
Does any body knows why the below mentioned code is not working in VC++ 6.0 compiler.
Here a Template function is kept as member and it will work only if the Template member function is defined within the class. i. e. without using scope resolution operator.
Does any one have idea regarding this error.
The error shown is

error C2893: Failed to specialize function template 'void __thiscall Stack::rush(T)'
With the following template arguments:


/***********************************
Class Stack
***********************************/
class Stack
{

private:

int nData;

public:

Stack();
template <class T> void rush( T Data );
};

/***********************************
Constructor
***********************************/

Stack::Stack() : nData( 0 )
{
}

/***********************************
Template Function for push.
***********************************/

template <class T> void Stack::rush( T Data )
{

}

int main()
{
Stack StkObj;
int nData = 10;
StkObj.rush( nData );
return 1;
}
May 2 '07 #1
3 1590
svlsr2000
181 Expert 100+
Template functions are allowed inside class. i am able to compile and run Your code without any difficulty under visual studio 2005.

You can also call function rush as below
Expand|Select|Wrap|Line Numbers
  1. [size=2]StkObj.rush<[/size][size=2][color=#0000ff]int[/color][/size][size=2]>( nData );
  2.  
  3. [/size]
May 2 '07 #2
svlsr2000
181 Expert 100+
i donno why i am able to see some html tags in my reply.

here is the code
[size=2]StkObj.rush<[/size][size=2][color=#0000ff]int[/color][/size][size=2]>( nData );

[/size]
May 2 '07 #3
ajayraj
21
I tried
StkObj.rush<int>( nData );
but didnt worked.
May be compiler specific problem.
May 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rennie deGraaf | last post by:
The attached code compiles and works properly when I comment out the declaration, definition, and invocations of the method 'eck'. With "eck" in there, g++ fails with ttest.cpp:23: template-id...
2
by: CoolPint | last post by:
As a self-exercise, I am trying to write a generic Priority Queue, which would store any type and and accept any user-definable "priority" function. After much tinkering, I came up with...
2
by: Alexander Stippler | last post by:
Hello, I want to write a non-template class with a constructor template member. The constructor shall not take arguments. Is this possible at all? Here the concrete example: A class which...
5
by: Steve | last post by:
Hi, Does C++ allow the programmer to declare a template with in a template so that a generic function can instantiate the embedded template? For example, could code such as this exist: ...
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...
12
by: jarradw | last post by:
I am trying to figure out if this will work. I have a template base class that I want to be able to inherit from, the classes that will need to inherit from this also need to be tamplates. Is this...
2
by: pascal.zschumme | last post by:
hello folks My problem is that the following code using something very very difficult technique :D fails to compile on MSVC8: <code> // main.cpp // // the error is: // main.cpp(8) : fatal...
3
by: Fei Liu | last post by:
Hello, We all know that a template function can automatically deduce its parameter type and instantiate, e.g. template <tpyename T> void func(T a); func(0.f); This will cause func<floatto...
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.