Ich versuche gerade mein Wissen in C++ zu vertiefen. Ich wollte jetzt eine einfache Klasse schreiben, dei mir den Computername ausgibt.
Das ganze sieht bis jetzt so aus:
main.cpp
CODE
#include <windows.h>
#include <string>
#include <stdio.h>
#include "getInformation.h"
#include <iostream>
int main()
{
getInformation info;
std::string name = info.getComputerName();
}
#include <string>
#include <stdio.h>
#include "getInformation.h"
#include <iostream>
int main()
{
getInformation info;
std::string name = info.getComputerName();
}
getInformation.h
CODE
#ifndef GETINFORMATION_H
#define GETINFORMATION_H
#include <string>
class getInformation
{
public:
getInformation();
virtual ~getInformation();
std::string getComputerName();
protected:
private:
};
#endif // GETINFORMATION_H
getInformation.cpp
CODE
#include "getInformation.h"
#include <windows.h>
#include <string>
#include <iostream>
using namespace std;
getInformation::getInformation()
{
//ctor
}
getInformation::~getInformation()
{
//dtor
}
string getComputerName() {
TCHAR chrComputerName[MAX_COMPUTERNAME_LENGTH + 1];
string strRetVal;
DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH + 1;
if(GetComputerName(chrComputerName,&dwBufferSize)) {
// We got the name, set the return value.
strRetVal = chrComputerName;
} else {
// Failed to get the name, call GetLastError here to get
// the error code.
strRetVal = "";
}
return(strRetVal);
}
Wenn ich versuche das ganze zu compilieren, bzw. zu linken, bekomme ich den Fehler:
undefined reference to `getInformation::getComputerName()'
Ankreiden tut er mir die Zeile std::string name = info.getComputerName();
Ist wahrscheinlich nur ein kleiner Anfänger-/Denkfehler. Allerdings komm ich einfach nicht drauf.
Danke und Gruß
divus
Dieser Beitrag wurde von divus bearbeitet: 07. Februar 2011 - 07:17