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

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\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
7 4242
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******@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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
4
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...
5
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,...
3
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...
6
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...
13
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...
9
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...
6
by: Ioannis Papadopoulos | last post by:
Hi, I have the following code: #include <iostream> int foo() { std::cout << __func__ << std::endl; }
1
by: Steve: | last post by:
Hi, With a normal class, I can do the following: --- class Foo; void func( Foo* param ); class Foo
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.