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:
Als Fehler wirft mir MS VC++ 6.0 immer nur:
Allerdings kann ich damit nichts anfangen weil es doch alles ganz richtig aussieht (oder?).
Verzweifelten Dank vorab
Quellen:
Aufruf:
Quelle der Klasse
Headerdatei der Klasse
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
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_)