----- hello, world 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;
}
----- hello.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;
}
----- The errors -----
- ------ Build started: Project: Hello, World 2, Configuration: Debug Win32 ------
- Hello, World 2.cpp
- Hello, World 2.cpp(12): error C2440: 'initializing' : cannot convert from 'hello *' to 'hello'
- No constructor could take the source type, or constructor overload resolution was ambiguous
- Hello, World 2.cpp(13): error C2039: 'getName' : is not a member of 'hello'
- \documents\visual studio 2010\projects\cpp\hello, world 2\hello, world 2\hello.h(8) : see declaration of '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) : see declaration of 'hello'
- hello.cpp(19): error C2065: '_fname' : undeclared identifier
- hello.cpp(19): error C2065: '_lname' : undeclared identifier
- Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========