By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

templated func : what's wrong

P: n/a
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\ustl\uutility.h(69) : error C2027: use of undefined type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2226: syntax error :
unexpected type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2988: unrecognizable template
declaration/definition
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2059: syntax error :
'<cv-qualifer>'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : 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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"mosfet" <jo******@anonymous.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\ustl\uutility.h(69) : error C2027: use of undefined type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2226: syntax error : unexpected
type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2988: unrecognizable template
declaration/definition
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2059: syntax error :
'<cv-qualifer>'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : 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

P: n/a
joe
On Aug 8, 3:48 am, mosfet <john....@anonymous.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\ustl\uutility.h(69) : error C2027: use of undefined type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2226: syntax error :
unexpected type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2988: unrecognizable template
declaration/definition
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2059: syntax error :
'<cv-qualifer>'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : 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

P: n/a
joe
On Aug 8, 3:48 am, mosfet <john....@anonymous.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\ustl\uutility.h(69) : error C2027: use of undefined type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2226: syntax error :
unexpected type 'T1'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2988: unrecognizable template
declaration/definition
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : error C2059: syntax error :
'<cv-qualifer>'
1>c:\program files\microsoft visual studio
8\vc\include\ustl\uutility.h(69) : 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

P: n/a
joe wrote:
:: On Aug 8, 3:48 am, mosfet <john....@anonymous.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\ustl\uutility.h(69) : error C2027: use of undefined
::: type 'T1' 1>c:\program files\microsoft visual studio
::: 8\vc\include\ustl\uutility.h(69) : error C2226: syntax error :
::: unexpected type 'T1'
::: 1>c:\program files\microsoft visual studio
::: 8\vc\include\ustl\uutility.h(69) : error C2988: unrecognizable
::: template declaration/definition
::: 1>c:\program files\microsoft visual studio
::: 8\vc\include\ustl\uutility.h(69) : error C2059: syntax error :
::: '<cv-qualifer>'
::: 1>c:\program files\microsoft visual studio
::: 8\vc\include\ustl\uutility.h(69) : 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 discussion thread is closed

Replies have been disabled for this discussion.