[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
help! complie error in gcc
From: |
chenjun . bj |
Subject: |
help! complie error in gcc |
Date: |
15 Sep 2006 08:44:26 -0700 |
User-agent: |
G2/1.0 |
I got an error when i compile the program list below under gcc, but
it's ok under vc6.0. I found that if i place the statement #include
<iostream> just before main or delete function _Ins, it's ok, but it
cannot work when i put it at the start of the file. who can help me,
many thanks!
//=---------------------------------------------------------------------------=
// isort.cxx
//=---------------------------------------------------------------------------=
#include <iostream>
/*
* value type of an iterator
* by stl
*/
template<class _Ty>
_Ty* value_type(_Ty*)
{ return ((_Ty*)0); }
template<class _RI, class _T>
void _Ins(_RI _L, _T _V)
{ for (_RI _M=_L; _V<*--_M; _L=_M) *_L = *_M;
*_L = _V;}
template<class _RI, class _Ty>
void _Insert_sort(_RI _IF, _RI _IL, _Ty* )
{
if (_IF != _IL){
for (++_IF; _IF<_IL; ++_IF){
_Ty V = *_IF;
_Ins(_IF, V);
}
}
}
template<class _RI>
void insert_sort(_RI first, _RI last)
{
_Insert_sort(first, last, value_type(first));
}
//#include <iostream>
int main()
{
int a[]={9,2,5,3,0,2,3,0,3};
insert_sort(a, a+9);
for (int k=0; k<9; ++k) std::cout << a[k] <<"\t";
std::cout << std::endl;
return 0;
}
=====error msg=====
$ g++ -g isort.cxx -o isort
isort.cxx:16: error: expected `,' or `...' before numeric constant
isort.cxx: In function `void _Ins(_RI)':
isort.cxx:17: error: `_V' undeclared (first use this function)
isort.cxx:17: error: (Each undeclared identifier is reported only once
for each
function it appears in.)
isort.cxx:17: error: invalid type argument of `unary *'
isort.cxx:18: error: invalid type argument of `unary *'
isort.cxx: In function `void _Insert_sort(_RI, _RI, _Ty*) [with _RI =
int*, _Ty
= int]':
isort.cxx:34: instantiated from `void insert_sort(_RI, _RI) [with
_RI
= int*]'
isort.cxx:43: instantiated from here
isort.cxx:26: error: no matching function for call to `_Ins(int*&,
int&)'
- help! complie error in gcc,
chenjun . bj <=