我有一个正在尝试编译的单一源文件 C++ 程序。
头文件如下所示:
class merge {
public:
explicit merge(int argc, char* argv[]);
virtual ~merge();
};
源文件如下所示:
int main(int argc, char* argv[])
{
merge mrg(argc,argv);
return 0;
}
merge::merge(map<string,string>& params) {
//code
}
尝试编译:g++ merge.cpp -o merge
我得到:
merge.cpp: In function ‘int main(int, char**)’:
merge.cpp:10: error: reference to ‘merge’ is ambiguous
merge.h:12: error: candidates are: class merge
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:3180: error: template<class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> _OutputIterator std::merge(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator, _Compare)
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:3122: error: template<class _InputIterator1, class _InputIterator2, class _OutputIterator> _OutputIterator std::merge(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator)
merge.cpp:10: error: reference to ‘merge’ is ambiguous
merge.h:12: error: candidates are: class merge
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:3180: error: template<class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> _OutputIterator std::merge(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator, _Compare)
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:3122: error: template<class _InputIterator1, class _InputIterator2, class _OutputIterator> _OutputIterator std::merge(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator)
merge.cpp:10: error: expected `;' before ‘mrg’
merge.cpp: At global scope:
merge.cpp:14: error: prototype for ‘merge::merge(std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)’ does not match any in class ‘merge’
merge.h:12: error: candidates are: merge::merge(const merge&)
merge.h:14: error: merge::merge(int, char**)
merge.cpp: In constructor ‘merge::merge(std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)’:
merge.cpp:15: error: declaration of ‘std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > params’ shadows a parameter
merge.cpp:16: error: ‘argc’ was not declared in this scope
merge.cpp:16: error: ‘argv’ was not declared in this scope
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_types.h: At global scope:
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_types.h: In instantiation of ‘std::iterator_traits<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’:
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:803: instantiated from ‘void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_InputIterator, _InputIterator, __false_type) [with _InputIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = int, _Alloc = std::allocator<int>]’
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:262: instantiated from ‘std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const _Alloc&) [with _InputIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = int, _Alloc = std::allocator<int>]’
merge.cpp:86: instantiated from here
/usr/lib/gcc/x86_64-redhat- linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_types.h:129: error: no type named ‘iterator_category’ in ‘struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’
知道有什么问题吗?