I know why linker errors occur but can't seem to see what the problem is here.
Picture of linker errors:
Header:
#ifndef DOWNLOAD_H
#define DOWNLOAD_H
#include <Windows.h>
class Download {
public:
Download();
Download(const char *URL, const char *FILE_NAME);
~Download();
LPCTSTR getURL() const;
LPCTSTR getFileName() const;
void setUrl(const char &URL) const;
void setFileName(const char &FILE_NAME) const;
void downloadFile();
private:
struct data_T;
};
#endif // DOWNLOAD_H
Cpp file:
#include "download.h"
struct Download::data_T {
const LPCTSTR &URL;
const LPCTSTR &FILE_NAME;
} *data;
Download::Download(){}
Download::Download(const char *URL, const char *FILE_NAME)
{
&data->FILE_NAME = &FILE_NAME;
&data->URL = &URL;
}
void Download::downloadFile()
{
HRESULT hr = URLDownloadToFile (0, &data.URL, &data.FILE_NAME, 0, 0);
switch (hr)
{
case S_OK: cout << "Successful download\n"; break;
case E_OUTOFMEMORY: cout << "Out of memory error\n"; break;
case INET_E_DOWNLOAD_FAILURE: cout << "Cannot access server data\n"; break;
default: cout << "Unknown error\n"; break;
}
printf("%x",hr);
}
void Download::setUrl(const LPCTSTR &URL) { &data.URL = URL; }
void Download::setFileName(const LPCTSTR &FILE_NAME) { &data.FILE_NAME = FILE_NAME; }
LPCTSTR Download::getUrl() const { return &data.URL; }
LPCTSTR Download::getFileName() const { return &data.FILE_NAME; }
Download::~Download()
{
delete this->data_T;
delete &data;
}
And this is how I initialize the class object and call a function:
Download dl("https://www.dropbox.com/s/rm9pszogafgm3e2/Cache_ver.txt?dl=0", "CACHE");
dl.downloadFile();
When building the executable, you need to link the specific libraries or the object files that contain the functions reported in the link error.