c++有关string的报错 “”声明与所属文件不兼容 急切求助!
环境vs2010
目的:想要实现string类型的参数传递,在头文件中声明,在源文件中定义
报错真心搞不明白。。。求助啊,各位!
//在头文件 a.h中代码如下:
#ifndef _STRING
#define _STRING
#endif
namespace a
{
class b
{
static __declspec(dllexport) string c(string str);
};
}
//在源文件helloworld.cpp中代码如下:
#include<iostream>
#include"a.h"
#include<string>
using namespace std;
using namespace a;
string b::c(string str) /*就在此处报错:IntelliSense: 声明与 "<error-type> a::b::c(<error-type> str)" (已声明 所在行数: 9,所属文件: "c:\documents and settings\administrator\my documents\visual studio 2010\projects\test\a.h") 不兼容 c:\documents and settings\administrator\my documents\visual studio 2010\projects\test\helloworld.cpp 66 17 test
*/
{
string s;
int len=str.length();
for(int i=0;i<len;i++)
{
s[i]=str[i];
}
return s;
}
//如果您看不明白的话可以加我qq:914351863
目的:想要实现string类型的参数传递,在头文件中声明,在源文件中定义
报错真心搞不明白。。。求助啊,各位!
//在头文件 a.h中代码如下:
#ifndef _STRING
#define _STRING
#endif
namespace a
{
class b
{
static __declspec(dllexport) string c(string str);
};
}
//在源文件helloworld.cpp中代码如下:
#include<iostream>
#include"a.h"
#include<string>
using namespace std;
using namespace a;
string b::c(string str) /*就在此处报错:IntelliSense: 声明与 "<error-type> a::b::c(<error-type> str)" (已声明 所在行数: 9,所属文件: "c:\documents and settings\administrator\my documents\visual studio 2010\projects\test\a.h") 不兼容 c:\documents and settings\administrator\my documents\visual studio 2010\projects\test\helloworld.cpp 66 17 test
*/
{
string s;
int len=str.length();
for(int i=0;i<len;i++)
{
s[i]=str[i];
}
return s;
}
//如果您看不明白的话可以加我qq:914351863
...全文
相关推荐
C++ 读文件 将文件内容读入到字符串string中的方法
如下所示: #include #include #include #include #include using namespace std; //从文件读入到string里 string readFileIntoString(char * filename) { ifstream ifile(filename); //将文件读入到ostringstream对象buf中 ostringstream buf; char ch; while(buf&&ifile.get(ch)) buf.put
C++中的extern声明变量详解
主要介绍了C++中的extern声明变量详解,本文讲解了声明和定义、extern声明全局变量、extern声明函数等内容,需要的朋友可以参考下
cpp代码-C++基础
cpp代码-C++基础
c++类声明和成员函数分离写法
c++将类成员函数实现与类的声明分离的写法,实现了学生类的分离写法
Dev C++编写C-C++程序 出现[Error] ld returned 1 exit status报错分析及解决.doc
Dev C++编写C-C++程序 出现[Error] ld returned 1 exit status报错分析及解决.doc


