Click here to Skip to main content
14,304,263 members

C / C++ / MFC

 
GeneralRe: The new upgrade system Pin
Richard MacCutchan29-Jul-18 0:50
protectorRichard MacCutchan29-Jul-18 0:50 
GeneralRe: The new upgrade system Pin
Anthony Appleyard29-Jul-18 18:20
memberAnthony Appleyard29-Jul-18 18:20 
GeneralRe: The new upgrade system Pin
Richard MacCutchan29-Jul-18 21:13
protectorRichard MacCutchan29-Jul-18 21:13 
GeneralRe: The new upgrade system Pin
Anthony Appleyard28-Jul-18 23:39
memberAnthony Appleyard28-Jul-18 23:39 
GeneralRe: The new upgrade system Pin
Anthony Appleyard28-Jul-18 23:39
memberAnthony Appleyard28-Jul-18 23:39 
GeneralRe: The new upgrade system Pin
Anthony Appleyard29-Jul-18 0:03
memberAnthony Appleyard29-Jul-18 0:03 
QuestionTrouble with the current automatic upgrade Pin
Anthony Appleyard28-Jul-18 19:50
memberAnthony Appleyard28-Jul-18 19:50 
Questionunique_ptr and make_unique -- [SOLVED] Pin
Richard Andrew x6427-Jul-18 17:58
professionalRichard Andrew x6427-Jul-18 17:58 
[See below the original question for the solution.]

I have been struggling with this for a while now, and I can't seem to figure it out.

Here's my declaration:

std::unique_ptr<BYTE*, std::function<void(BYTE**)>>     _VersionData{};

And here's where I attempt to instantiate it:
_VersionData = std::make_unique<BYTE*>(new BYTE[_VersionDataLength], [](BYTE** ptr) {delete *ptr; }); // Attempting to use a lambda expression as a custom destructor

The errors I receive are:
error C2440: 'initializing': cannot convert from 'initializer list' to 'unsigned char *'
note: The initializer contains too many elements


I'm probably way off in my interpretation of the documentation. Can someone show me how this is supposed to work? Smile | :)


[SOLUTION]

Turns out I was really way off with the attempt shown above.

Here's the working code.

The declaration in the class header file:
std::unique_ptr<BYTE, void(*)(BYTE*)>                 _VersionData;

The instantiation in the source file:
auto CustomDeleter = [](BYTE* ptr) {delete[] ptr; };

_VersionData = std::unique_ptr<BYTE, decltype(CustomDeleter)>(new BYTE[_VersionDataLength], CustomDeleter);

And the most important part, the constructor initializer list:
CFileVersionInfo::CFileVersionInfo()
	: _VersionData(nullptr, [](BYTE* ptr) {delete[] ptr; })
{
   // constructor code here...
}




The difficult we do right away...
...the impossible takes slightly longer.


modified 28-Jul-18 11:42am.

AnswerRe: unique_ptr and make_unique -- [SOLVED] Pin
Richard MacCutchan28-Jul-18 6:00
protectorRichard MacCutchan28-Jul-18 6:00 
GeneralRe: unique_ptr and make_unique -- [SOLVED] Pin
Richard Andrew x6428-Jul-18 11:06
professionalRichard Andrew x6428-Jul-18 11:06 
QuestionWhere I can learn about using wsprintf? Pin
GESY26-Jul-18 8:01
memberGESY26-Jul-18 8:01 
AnswerRe: Where I can learn about using wsprintf? Pin
Victor Nijegorodov26-Jul-18 8:25
memberVictor Nijegorodov26-Jul-18 8:25 
AnswerRe: Where I can learn about using wsprintf? Pin
Joe Woodbury26-Jul-18 8:26
professionalJoe Woodbury26-Jul-18 8:26 
GeneralRe: Where I can learn about using wsprintf? Pin
GESY26-Jul-18 16:25
memberGESY26-Jul-18 16:25 
GeneralRe: Where I can learn about using wsprintf? Pin
Joe Woodbury26-Jul-18 17:45
professionalJoe Woodbury26-Jul-18 17:45 
GeneralRe: Where I can learn about using wsprintf? Pin
GESY27-Jul-18 4:05
memberGESY27-Jul-18 4:05 
GeneralRe: Where I can learn about using wsprintf? Pin
GESY27-Jul-18 4:07
memberGESY27-Jul-18 4:07 
AnswerRe: Where I can learn about using wsprintf? Pin
Richard MacCutchan26-Jul-18 22:13
protectorRichard MacCutchan26-Jul-18 22:13 
QuestionReturn nothing from a function having return type Pin
meerokh26-Jul-18 0:40
membermeerokh26-Jul-18 0:40 
AnswerRe: Return nothing from a function having return type Pin
Richard MacCutchan26-Jul-18 1:28
protectorRichard MacCutchan26-Jul-18 1:28 
GeneralRe: Return nothing from a function having return type Pin
Member 1392860827-Jul-18 11:43
memberMember 1392860827-Jul-18 11:43 
GeneralRe: Return nothing from a function having return type Pin
Richard MacCutchan27-Jul-18 21:54
protectorRichard MacCutchan27-Jul-18 21:54 
AnswerRe: Return nothing from a function having return type Pin
Jochen Arndt26-Jul-18 1:48
mveJochen Arndt26-Jul-18 1:48 
AnswerRe: Return nothing from a function having return type Pin
Joe Woodbury26-Jul-18 5:44
professionalJoe Woodbury26-Jul-18 5:44 
QuestionNo Errors but wrong values on return? Pin
GESY25-Jul-18 16:02
memberGESY25-Jul-18 16:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.