473,791 Members | 3,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

templated func : what's wrong

HI,

when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :

/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>
inline const T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);
}

1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2027: use of undefined type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2226: syntax error :
unexpected type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2988: unrecognizable template
declaration/definition
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error :
'<cv-qualifer>'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error : ')'
I think it comes from the fact template functions like this are not
standard C++.
Could someone confirm ?

How can I change that ?
Aug 8 '07 #1
7 4270
mosfet wrote:
HI,

when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :

/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>
inline const T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);
}
There's nothing wrong with the above, maybe you have disabled templates?
>
I think it comes from the fact template functions like this are not
standard C++.
Could someone confirm ?
What's non-standard about it?

--
Ian Collins.
Aug 8 '07 #2
Ian Collins a écrit :
mosfet wrote:
>HI,

when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :

/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>
inline const T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);
}
There's nothing wrong with the above, maybe you have disabled templates?
>I think it comes from the fact template functions like this are not
standard C++.
Could someone confirm ?
What's non-standard about it?
I thought that now you cannot declare "global" templates without class
keyword.

When I look at MSDN doc here is whar I see :

The summary is optional.

The template declaration specifies a set of parameterized classes or
functions.
template < template-parameter-list declaration
Remarks
The template-parameter-list is a comma-separated list of template
parameters, which may be types (in the form class identifier, typename
identifier, or template < template-parameter-list class identifier) or
non-type parameters to be used in the template body. The syntax for a
template parameter is one of the following:

Copy Code
parameter-declaration
class identifier [ = typename ]
typename identifier [ = typename ]
template < template-parameter-list class [identifier][= name]
You can instantiate a class template much like you would instantiate a
normal class, but you must include the template arguments within angle
brackets (<>). These template arguments can be any type if the template
argument list contains the class or typename keyword, or a value of the
appropriate type if the argument is a non-type argument. No special
syntax is required to call a function template, although the angle
brackets and template arguments can be required if the template
parameters cannot be deduced from the arguments to the function.

The template-parameter-list is a list of parameters used by the template
function that specifies which parts of the following code will vary. For
example:

Copy Code
template< class T, int i class MyStack...
In this case, the template can receive a type (class T) and a constant
parameter (int i). The template will use type T and the constant integer
i upon instantiation. Within the body of the MyStack declaration, you
must refer to the T identifier.

A template declaration itself does not generate code; it specifies a
family of classes or functions, one or more of which will be generated
when referenced by other code.

Template declarations have global, namespace, or class scope. They
cannot be declared within a function.
Aug 8 '07 #3
mosfet wrote:
Ian Collins a écrit :
>mosfet wrote:
>>HI,

when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :

/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>
inline const T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);
}
There's nothing wrong with the above, maybe you have disabled templates?
>>I think it comes from the fact template functions like this are not
standard C++.
Could someone confirm ?
What's non-standard about it?
I thought that now you cannot declare "global" templates without class
keyword.
You have written a function template, how were you using it to get that
error?

Something like:

int main() {
int a = 0;
short b = 3;

int c = min(a, b);
}

--
Ian Collins.
Aug 8 '07 #4
"mosfet" <jo******@anony mous.orgwrote in message
news:46******** **************@ news.free.fr...
HI,

when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :

/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>
inline const T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);
}

1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2027: use of undefined type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2226: syntax error : unexpected
type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2988: unrecognizable template
declaration/definition
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error :
'<cv-qualifer>'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error : ')'
I think it comes from the fact template functions like this are not
standard C++.
Could someone confirm ?

How can I change that ?
I get a warning when I compile your code, I thought it wouldn't even
compile. When I remove the first "const" the error goes away. What is that
const suppoed to mean? Try this isntead:

template <typename T1, typename T2>
inline T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);
}

Note: changed from inline const T1 to inline T1

That const there doesn't make much sense to the compiler, or me.
Aug 8 '07 #5
joe
On Aug 8, 3:48 am, mosfet <john....@anony mous.orgwrote:
HI,

when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :

/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>
inline const T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);

}

1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2027: use of undefined type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2226: syntax error :
unexpected type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2988: unrecognizable template
declaration/definition
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error :
'<cv-qualifer>'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error : ')'

I think it comes from the fact template functions like this are not
standard C++.
Could someone confirm ?

How can I change that ?
Have you stumbled across a 'min' macro from else where? MS defines
one in the set of headers declared in windows.h. If you have, you can
fix that by invoking the function with the syntax

int a = (min)(5,6);

Surrounding the function name with parenthesis forces the preprocessor
to not match the function and to instead use the template.

joe

Aug 8 '07 #6
joe
On Aug 8, 3:48 am, mosfet <john....@anony mous.orgwrote:
HI,

when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :

/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>
inline const T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);

}

1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2027: use of undefined type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2226: syntax error :
unexpected type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2988: unrecognizable template
declaration/definition
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error :
'<cv-qualifer>'
1>c:\program files\microsoft visual studio
8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error : ')'

I think it comes from the fact template functions like this are not
standard C++.
Could someone confirm ?

How can I change that ?
Btw, it compiles for me as is on VC 8.0

joe

Aug 8 '07 #7
joe wrote:
:: On Aug 8, 3:48 am, mosfet <john....@anony mous.orgwrote:
::: HI,
:::
::: when trying to compile an embedded version of STL called ustl on
::: win32 platform I get the following error :
:::
::: /// Returns the minimum of \p a and \p b
::: template <typename T1, typename T2>
::: inline const T1 min (const T1& a, const T2& b)
::: {
::: return (a < b ? a : b);
:::
::: }
:::
::: 1>c:\program files\microsoft visual studio
::: 8\vc\include\us tl\uutility.h(6 9) : error C2027: use of undefined
::: type 'T1' 1>c:\program files\microsoft visual studio
::: 8\vc\include\us tl\uutility.h(6 9) : error C2226: syntax error :
::: unexpected type 'T1'
::: 1>c:\program files\microsoft visual studio
::: 8\vc\include\us tl\uutility.h(6 9) : error C2988: unrecognizable
::: template declaration/definition
::: 1>c:\program files\microsoft visual studio
::: 8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error :
::: '<cv-qualifer>'
::: 1>c:\program files\microsoft visual studio
::: 8\vc\include\us tl\uutility.h(6 9) : error C2059: syntax error : ')'
:::
::: I think it comes from the fact template functions like this are
::: not standard C++.
::: Could someone confirm ?
:::
::: How can I change that ?
::
:: Btw, it compiles for me as is on VC 8.0
::
:: joe

It depends on the settings, and what headers you include.

On VC way to get rid of these macros is the define the macro NOMINMAX
in you project settings.
Bo Persson
Aug 8 '07 #8

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

Similar topics

1
1870
by: Rich | last post by:
Hi, I have a query regarding VC6 and its handling of templated copy constructors. Here goes: Take a look at the following code sample... template<class _Ty, size_t t_uiSize = 10 > class my_template
4
1529
by: Tomas Ukkonen | last post by:
Hi I'm currently trying to make my old code to compile with new gcc 3.4.0. It compiles correctly in 3.3.3 so I'm not sure if this is compiler bug or not. Code very close to a example below fails to compile because gcc 3.4.0 complains: "error: expected a type got 'Y<T>::particle'"
5
5646
by: Pete C. | last post by:
I'm trying to make a templated function a friend like this: class cls { ... friend cls func<> (const cls& a, const cls& b); }; template< template<class> class Op> cls func (const cls& a, const cls& b)
3
2733
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 Foo> class Bar { private: Foo foo;
6
1973
by: __PPS__ | last post by:
it's ok according to the standard to specialize member function like this: template<class T>struct xxx { void func(); }; template<>bool xxx<int>::func(){ //int version } template<>bool xxx<double>::func(){
13
2236
by: algorimancer | last post by:
I use the STL collection classes a lot, and frequently find myself writing something like: vector<CDataClass>::iterator iter=DataClassCollection.begin(); vector<CDataClass>::iterator iter_end=DataClassCollection.end(); for(;iter!=iter_end;++iter) { //doing stuff with iter... }
9
1847
by: shaun | last post by:
I am working on code where I am handed a vector of pointers vector<T*> or a map<std::string, T*>, and I have to delete the objects and set the pointers to zero. I have been using a 'for' loop and thought it might be instructive to write a 'deletePointer' which can be used in an algorithm or standalone. (code at end of mail) I discovered I could not simply for_each(v.begin(),v.end(),deletePointer);
6
1498
by: Ioannis Papadopoulos | last post by:
Hi, I have the following code: #include <iostream> int foo() { std::cout << __func__ << std::endl; }
1
1478
by: Steve: | last post by:
Hi, With a normal class, I can do the following: --- class Foo; void func( Foo* param ); class Foo
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10147
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.