[ create a new paste ] login | about

Link: http://codepad.org/HWxjYvDk    [ raw code | output | fork ]

C++, pasted on Jul 27:
#include <fstream>
 
class FileClient
{
protected:
    char* p;
public:
 
    virtual void connect() = 0;
    void close(){}
    virtual void ping()
    {
        printf("%s : %s", "__FUNCTION__", p);
    }
    FileClient()
    {
        p = new char[10];
        p[0] = '1';
    }
    ~FileClient()
    {
        delete p;
    }
};
class Client : public FileClient
{
    FILE* hFile;
public:
    Client() : hFile( NULL ) {}//кто обнулять будет?
    virtual void connect(){
        //глупая функция путь к файлу и параметры следует передават ьв функцию а не забивать
        hFile = fopen("D:\\test.txt", "w");
    }
    void ping()
    {
        char arr[] = { 0, 0, 5, 56, 12, 32 };
        fwrite(arr, 1, sizeof(arr), hFile);
        FileClient::ping();
    }
    ~Client()
    {
        if( p )
        delete[] p;
        p = 0;
        if( hFile )
            fclose(hFile);
    }
};
 
int main()
{
    FileClient* client = new Client;
    client->connect();
    client->ping();
    delete client;
}


Output:
1
__FUNCTION__ : 1����������


Create a new paste based on this one


Comments: