/*****************************文件tt.h***********************************/
1 class string;
2 string *tt();
1 #include <iostream>
2 #include <string>
3 #include "tt.h"
4
5 using namespace std;
6 string *tt(){
7 return new string("dddddd");
8 }
9 int main(int argc, const char *argv[])
10 {
11
12 return 0;13 }
g++版本:
g++ (GCC) 4.4.4 20100726 (Red Hat 4.4.4-13)
g++ tt.cpp tt.h 出现以下错误:
tt.cpp:6: 错误:对‘string’的引用有歧义
tt.h:1: 错误:candidates are: struct string
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/bits/stringfwd.h:56: 错误: typedef struct std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::string
tt.cpp:6: 错误:expected constructor, destructor, or type conversion before ‘*’ token
不在头文件中加入#include <string>和using std::string;请大家帮忙看看什么问题?
本文探讨了C++编程中遇到的一个常见问题:当使用标准库中的string类型时出现的引用歧义错误。文中通过具体的代码示例,详细解释了如何正确地包含必要的头文件并使用命名空间来避免此类编译错误。
452

被折叠的 条评论
为什么被折叠?



