Undefinied reference to... beim benutzen von Klasse

FBIagent

Erfahrenes Mitglied
Moin,

ich habe mal wieder ein Problemchen...
Ich habe folgendes:
main.cpp
Code:
#include <iostream>
#include "log.h"

log chatLog;
log gmActionLog;
log playerActionLog;

int i;

int main()
{
  chatLog.open("chat.log");
  gmActionLog.open("gmAction.log");
  playerActionLog.open("playerAction.log");
  
  for(;;)
  {
    std::cin >> i;
    
    switch(i)
    {
      case 1: chatLog.write("The chatlog.");
              break;
      case 2: gmActionLog.write("The GM actions log.");
              break;
      case 3: playerActionLog.write("The player actions log.");
              break;
    }
    
    if(i==0)
      break;
  }
  
  chatLog.close();
  gmActionLog.close();
  playerActionLog.close();

  return 0;
}

log.h / log.cpp
Code:
#ifndef MY_LOG_H
#define MY_LOG_H

#include <iostream>
#include <fstream>
#include <time.h>
#include "extraStrings.h"

class log
{
private:
  std::ofstream logFileStream;
  extraStrings extraStr;
public:
  std::string formatDate(int data);
  void setFile(std::string data);
  bool open(std::string data);
  void write(std::string data);
  void close();
};

#endif
------------------------------------------------------------------------------------------------------------------------------
#include "log.h"

std::string log::formatDate(int data)
{  
  if(data<10)
    return "0" + extraStr.intToStr(data);
  
  return extraStr.intToStr(data);
}

bool log::open(std::string data)
{
  logFileStream.open(data.c_str());
  
  if(!logFileStream.is_open())
    return false;
    
  return true;
}

void log::write(std::string data)
{
  time_t fullSec = time(0);
  tm *time = localtime(&fullSec);
 
  logFileStream << "[";
  logFileStream << formatDate(time->tm_mday) << ".";
  logFileStream << formatDate(time->tm_mon+1) << ".";
  logFileStream << formatDate(time->tm_year+1900) << " - ";
  logFileStream << formatDate(time->tm_hour) << ":";
  logFileStream << formatDate(time->tm_min) << ":";
  logFileStream << formatDate(time->tm_sec) << "]";
  logFileStream << data << "\n";
}

void log::close()
{
  logFileStream.close();
}

extraStrings.h / extraStrings.cpp
Code:
#ifndef MY_EXTRASTRINGS_H
#define MY_EXTRASTRINGS_H

#include <sstream>

class extraStrings
{
public:
  template<class T> std::string intToStr(T t);
};

#endif
------------------------------------------------------------------------------------------------------------------------------
#include "extraStrings.h"

template<class T> std::string extraStrings::intToStr(T t)
{
  std::basic_ostringstream<char> strFromInt;

  strFromInt << t;
  std::string returnStr(strFromInt.str());

  returnStr.resize(returnStr.length());

  return returnStr;
}

Nur leider bekomme ich immer folgende meldung:
Code:
C:\DOKUME~1\FBIagent\LOKALE~1\Temp/ccELdaaa.o(.text+0x160):log.cpp: undefinied reference to `std::string extraStrings::intToStr<int>(int)'

Ich Kompiliere es wie volgt:
Code:
g++ *.cpp -o log.exe

Hm... ich weis so langsam nicht mehr weiter vieleicht könnt ihr mir ja helfen.

THX im Vorraus
MFG FBIagent
 
Zuletzt bearbeitet:
Zurück