Good afternoon. I am starting with Visual c++ and I have a compilation problem I dont understand.
The Errors I get are the following :
error LNK1120 external links unresolved
error LNK2019
I paste the code:
C++TestingConsole.CPP
#include "stdafx.h"
#include "StringUtils.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
string res = StringUtils::GetProperSalute("Carlos").c_str();
cout << res;
return 0;
}
StringUtils.cpp
#include "StdAfx.h"
#include <stdio.h>
#include <ostream>
#include "StringUtils.h"
#include <string>
#include <sstream>
using namespace std;
static string GetProperSalute(string name)
{
return "Hello" + name;
}
Header: StringUtils.h
#pragma once
#include <string>
using namespace std;
class StringUtils
{
public:
static string GetProperSalute(string name);
};
You only need to declare the method
staticin the class definition and qualify it with the class name when you define it:should be
Other notes:
using namespace std;. Prefer full qualifications (e.g.std::string)StringUtilsseems like it would be better suited as anamespace(this will imply more changes to the code)string res = StringUtils::GetProperSalute("Carlos").c_str();is useless, you can just do:string res = StringUtils::GetProperSalute("Carlos");constreference instead of by value:std::string GetProperSalute(std::string const& name)