WinFuture-Forum.de: [gelöst] undefined reference to - WinFuture-Forum.de

Zum Inhalt wechseln

Nachrichten zum Thema: Entwicklung
Seite 1 von 1

[gelöst] undefined reference to


#1 Mitglied ist offline   divus 

  • Gruppe: aktive Mitglieder
  • Beiträge: 36
  • Beigetreten: 28. Januar 06
  • Reputation: 0

  geschrieben 04. Februar 2011 - 07:56

Hallo zusammen. Ich hoffe ihr könnt mir helfen.

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();

}


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

0

Anzeige



#2 Mitglied ist offline   Andi_84 

  • Gruppe: aktive Mitglieder
  • Beiträge: 401
  • Beigetreten: 30. November 08
  • Reputation: 1
  • Geschlecht:Männlich
  • Wohnort:Bayern

geschrieben 04. Februar 2011 - 14:35

Der Fehler liegt hier: getInformation.cpp
string getComputerName() {
...

^^ Das muss:
string getInformation::getComputerName() {
...

heißen.

Viele Grüße,
Анди
Laptop: HP EliteBook 8560p; Core i7-2720QM, 16 GB DDR3 1333, 500 GB HDD, Intel HD Graphics 3000, Win 7 x64 SP1 Build 7601.17514
Internetzugang: T-Home VDSL 50 @ 51392 kbit/s down, 10048 kbit/s up || Router: FritzBox 7360 @ FW 111.05.24
0

#3 Mitglied ist offline   divus 

  • Gruppe: aktive Mitglieder
  • Beiträge: 36
  • Beigetreten: 28. Januar 06
  • Reputation: 0

geschrieben 07. Februar 2011 - 07:15

Und deswegen such ich zwei Tage rum -.-
Hätt ich eigentlich selber sehen müssen.

Danke dir!

Gruß divus
0

Thema verteilen:


Seite 1 von 1

1 Besucher lesen dieses Thema
Mitglieder: 0, Gäste: 1, unsichtbare Mitglieder: 0