Newbie: Klasse will nicht instanziert werden

RealBastie

Grünschnabel
Hallo,
ich bin was OO mit C++ angeht relativ neu und versuche mich an einer Beispielklasse um etwas ins Thema zu kommen. Im Prinzip geht folgendes nicht:
Code:
  myapi::io::File datei = new myapi::io::File (path);

Als Fehler wirft mir MS VC++ 6.0 immer nur:
Code:
error C2440: 'initializing' : 'class myapi::io::File *' kann nicht in 'class myapi::io::File' konvertiert werden
Quelltyp konnte von keinem Konstruktor angenommen werden, oder die Ueberladungsaufloesung des Konstruktors ist mehrdeutig
Allerdings kann ich damit nichts anfangen weil es doch alles ganz richtig aussieht (oder?).

Verzweifelten Dank vorab


Quellen:
Aufruf:
Code:
#include "stdafx.h"
#include <windows.h>
#include "C:\Dokumente und Einstellungen\All Users\myAPI\myAPI\File.h"

int main(int argc, char* argv[]) {
  HINSTANCE myAPI = LoadLibrary ("myAPI.dll");
  char* path = "c:\\";
  myapi::io::File datei = new myapi::io::File (path);
  printf (path);
  return 0;
}

Quelle der Klasse
Code:
// File.cpp: Implementierung der Klasse File.
//
//////////////////////////////////////////////////////////////////////

#include "File.h"
//#include <dir.h>      /* MS-DOS/WIN */

namespace myapi {
  namespace io {

    File::File (char* path) {
      this->path = path;
    }

    File::~File() {
      this->path = NULL;
    }

    bool File::exist () {
      return false;
    }

    char* File::toString () {
      return this->path;
    }
  
    bool File::isDirectory () {
      _stat(this->path, &this->fileInfo);
      return false;
    }

    bool File::isFile () {
      _stat(this->path, &this->fileInfo);
      return false;
    }


    bool File::makeDirectory () {
      return (_mkdir(this->path) == 0);
    }

    bool File::del () {
      return (remove (this->path) == 0);   // int=>bool
      //return (_unlink(this->path) == 0); // what is better?
    }

    bool File::rename (char* newName) {
      bool ok = (rename (newName) == 0);
      if (ok) {
        this->path = newName;
      }
      return ok;
    }
  
  }
}

Headerdatei der Klasse
Code:
// File.h: Schnittstelle für die Klasse File.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FILE_H__04ED1E0E_E02D_4C24_BCD8_C2513068DD89__INCLUDED_)
  #define AFX_FILE_H__04ED1E0E_E02D_4C24_BCD8_C2513068DD89__INCLUDED_

  #if _MSC_VER > 1000
  #pragma once
#endif // _MSC_VER > 1000

#include "stdio.h"
#include <direct.h>     /* Visual C++ */

namespace myapi {
	namespace io {
		class File {
			public:
				File(char* path);
				virtual ~File();
        bool exist();
        bool isDirectory ();
        bool isFile ();
        bool makeDirectory ();
        bool del ();
        bool rename (char* newName);
        char* toString();
      private:
        char* path;
        struct _stat fileInfo;
		};
	}
}

#endif // !defined(AFX_FILE_H__04ED1E0E_E02D_4C24_BCD8_C2513068DD89__INCLUDED_)
 
Hallo,

probier das Erstellen mal so:
Code:
myapi::io::File *datei = new myapi::io::File (path);

MfG Turri
 
Danke für die schnelle Antwort. Der Compiler ist nun ruhig - dafür ist der Linker jetzt etwas aufmüpfig:

Bei Variante 1...
Code:
myapi::io::File* datei = new myapi::io::File (path);
...meint der Linker:
Code:
TestmyAPI.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: __thiscall myapi::io::File::File(char *)" (0File@io@myapi@@QAE@PAD@Z)

Bei Variante 2...
Code:
myapi::io::File datei(path);
...meint der Linker sogar
Code:
TestmyAPI.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: virtual __thiscall myapi::io::File::~File(void)" (1File@io@myapi@@UAE@XZ)
TestmyAPI.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: __thiscall myapi::io::File::File(char *)" (0File@io@myapi@@QAE@PAD@Z)
D
 
Nun zumindest hatte ich dies nicht vor. Ich wollte eigentlich dann meine Klassen in eine DLL packen. Falls es hilft: Ich habe unter VC 6 im Arbeitsbereich zwei Projekte einmal für die DLL und einmal für den hier angesprochenen Test. Die DLL aus dem DLL-Projekt habe ich dann noch in das Debug Verzeichnis meines Test-Projektes kopiert.
 

Neue Beiträge

Zurück