【发布时间】:2011-03-11 23:14:19
【问题描述】:
-----你好,世界 2.cpp -----
// Hello, World 2.cpp : main project file.
#include "stdafx.h"
#include "hello.h"
#include <string>
using namespace System;
using namespace std;
int main(array<System::String ^> ^args)
{
hello hi = new hello("Bob", "Blacksmith");
Console::WriteLine(L"Hello, " + hi.getName + "!");
return 0;
}
--你好.h -----
#include <string>
using namespace std;
#ifndef HELLO_H
#define HELLO_H
class hello
{
private:
string _fname;
string _lname;
//hello() { } // private default constructor
public:
hello(string fname, string lname);
void SetName(string fname, string lname);
string GetName();
};
#endif
----- hello.cpp -----
#include "stdafx.h"
#include "hello.h"
#include <string>
using namespace std;
hello::hello(string fname, string lname)
{
SetName(fname, lname);
}
void hello::SetName(string fname, string lname)
{
_fname = fname;
_lname = lname;
}
string hello::getName()
{
return _fname + _lname;
}
----- 错误-----
- ----- 构建开始:项目:Hello, World 2,配置:调试 Win32 ------
- 你好,世界 2.cpp
- 你好,世界 2.cpp(12):错误 C2440:“正在初始化”:无法从“你好 *”转换为“你好”
- 没有构造函数可以采用源类型,或者构造函数重载决策不明确
- 你好,世界 2.cpp(13):错误 C2039:“getName”:不是“hello”的成员
- \documents\visual studio 2010\projects\cpp\hello, world 2\hello, world 2\hello.h(8) : 参见“hello”的声明
- hello.cpp
- hello.cpp(17): error C2039: 'getName' : is not a member of 'hello'
- \documents\visual studio 2010\projects\cpp\hello, world 2\hello, world 2\hello.h(8) : 参见“hello”的声明
- hello.cpp(19):错误 C2065:“_fname”:未声明的标识符
- hello.cpp(19):错误 C2065:“_lname”:未声明的标识符
- 正在生成代码... ========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
【问题讨论】:
标签: c++-cli