Click here to Skip to main content
15,898,134 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionQtimer class in Qt Pin
sara7431-May-14 20:17
sara7431-May-14 20:17 
AnswerRe: Qtimer class in Qt Pin
Richard MacCutchan31-May-14 21:03
mveRichard MacCutchan31-May-14 21:03 
AnswerThe QElapsedTimer Class has timer.elapsed( ) built in. Pin
Software_Developer31-May-14 21:13
Software_Developer31-May-14 21:13 
GeneralRe: The QElapsedTimer Class has timer.elapsed( ) built in. Pin
sara741-Jun-14 1:25
sara741-Jun-14 1:25 
QuestionThe Ultimate Toolbox file watcher links are dead Pin
Grine Amine31-May-14 5:51
Grine Amine31-May-14 5:51 
AnswerRe: The Ultimate Toolbox file watcher links are dead Pin
Richard MacCutchan31-May-14 21:01
mveRichard MacCutchan31-May-14 21:01 
AnswerRe: The Ultimate Toolbox file watcher links are dead Pin
David Crow1-Jun-14 16:58
David Crow1-Jun-14 16:58 
Questionwhy can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
Falconapollo28-May-14 21:02
Falconapollo28-May-14 21:02 
I'm using Visual Studio 2013.
I don't konw why get crash in these following scenarios. What am I missing?
Crash in this function:
C++
extern "C" _CRTIMP int __cdecl _CrtIsValidHeapPointer(
        const void * pUserData
        )
{
        if (!pUserData)
            return FALSE;

        if (!_CrtIsValidPointer(pHdr(pUserData), sizeof(_CrtMemBlockHeader), FALSE))
            return FALSE;

        return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}


Scenario 1:
C++
std::shared_ptr<int> foo()
{
	std::shared_ptr<int> p(new int(10));
	size_t cnt = 10;
	while (cnt--)
		p.get()[cnt] = roll_die();

	return p;                   
}

void func(int* ptr, size_t cnt)
{
	while (cnt--)
	{
		cout << ptr[cnt] << endl;
	}
}

void main()
{
	std::shared_ptr<int> u_ptr = nullptr;
	u_ptr = foo();
	func(u_ptr.get(), 10);
}


Scenario 2:
C++
std::unique_ptr<int> foo()
{
	std::unique_ptr<int> p(new int(10));
	size_t cnt = 10;
	while (cnt--)
		p.get()[cnt] = roll_die();

	return p;                   
}

void func(int* ptr, size_t cnt)
{
	while (cnt--)
	{
		cout << ptr[cnt] << endl;
	}
}

void main()
{
	std::unique_ptr<int> u_ptr = nullptr;
	u_ptr = foo();
	func(u_ptr.get(), 10);
}


modified 29-May-14 4:52am.

AnswerRe: why can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
CPallini28-May-14 22:45
mveCPallini28-May-14 22:45 
GeneralRe: why can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
Falconapollo28-May-14 22:53
Falconapollo28-May-14 22:53 
GeneralRe: why can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
CPallini29-May-14 0:17
mveCPallini29-May-14 0:17 
GeneralRe: why can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
Richard MacCutchan29-May-14 0:35
mveRichard MacCutchan29-May-14 0:35 
GeneralRe: why can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
CPallini29-May-14 0:40
mveCPallini29-May-14 0:40 
GeneralRe: why can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
Richard MacCutchan29-May-14 0:43
mveRichard MacCutchan29-May-14 0:43 
GeneralRe: why can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
CPallini29-May-14 1:00
mveCPallini29-May-14 1:00 
AnswerRe: why can't I use std::shared_ptr & std::unique_ptr like this? just got crash Pin
Randor 29-May-14 0:18
professional Randor 29-May-14 0:18 
QuestionMFC -Help Pin
imran.prdc27-May-14 19:46
imran.prdc27-May-14 19:46 
AnswerRe: MFC -Help Pin
_Flaviu27-May-14 20:24
_Flaviu27-May-14 20:24 
AnswerRe: MFC -Help Pin
Richard MacCutchan27-May-14 21:14
mveRichard MacCutchan27-May-14 21:14 
GeneralRe: MFC -Help Pin
imran.prdc27-May-14 21:16
imran.prdc27-May-14 21:16 
GeneralRe: MFC -Help Pin
imran.prdc27-May-14 21:16
imran.prdc27-May-14 21:16 
GeneralRe: MFC -Help Pin
Richard MacCutchan27-May-14 21:29
mveRichard MacCutchan27-May-14 21:29 
GeneralRe: MFC -Help Pin
Stefan_Lang27-May-14 21:30
Stefan_Lang27-May-14 21:30 
QuestionRegQueryValueEx returns wrong value Pin
vks1125-May-14 23:57
vks1125-May-14 23:57 
AnswerRe: RegQueryValueEx returns wrong value Pin
Richard MacCutchan26-May-14 0:26
mveRichard MacCutchan26-May-14 0:26 

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.