Click here to Skip to main content
15,892,927 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Release VS Debug compiles Pin
Richard MacCutchan1-Feb-11 4:21
mveRichard MacCutchan1-Feb-11 4:21 
GeneralRe: Release VS Debug compiles Pin
Khan Shere1-Feb-11 5:01
Khan Shere1-Feb-11 5:01 
GeneralRe: Release VS Debug compiles Pin
Richard MacCutchan1-Feb-11 6:13
mveRichard MacCutchan1-Feb-11 6:13 
AnswerRe: Release VS Debug compiles Pin
Andrew Brock1-Feb-11 4:50
Andrew Brock1-Feb-11 4:50 
GeneralRe: Release VS Debug compiles [modified] Pin
Aescleal1-Feb-11 7:58
Aescleal1-Feb-11 7:58 
AnswerRe: Release VS Debug compiles Pin
User 74293381-Feb-11 10:02
professionalUser 74293381-Feb-11 10:02 
GeneralRe: Release VS Debug compiles Pin
Khan Shere1-Feb-11 20:57
Khan Shere1-Feb-11 20:57 
Questionuse the member pointer via a Get function and allocate memory outside, not clear why in this way Pin
George Nistor1-Feb-11 1:36
George Nistor1-Feb-11 1:36 
hi guys

probably already discussed but I did not find the explenation:
in the above code:

My question is why I have to use reference to the pointer
when returning from mGetPt?

If this pointer whould have been used inside the function,
and for example used in constructor to allocate memory
if I have an Get function like CInner* mGetPt(void)
I am able to use the pointer as I want.

but in the above example it is required to return a reference.
(this is the return value, is not a function param; OK I know in case of function params I have to use reference to pinter)
Please someone clarify me why?

class CInner
{
public:
	int mx;

	CInner()
	{
		mx=1;
	}
};

class CTest
{
private:
	CInner *pt;

public:
	CTest()
	{
		pt= NULL;
	}

	CInner*& mGetPt(void)
	{
		return pt;
	}

};

int _tmain(int argc, _TCHAR* argv[])
{
	CTest *obj= new CTest();
	
	obj->mGetPt() = new CInner();

	cout<<obj->mGetPt()->mx;

	cin.get();
	return 0;
}

AnswerRe: use the member pointer via a Get function and allocate memory outside, not clear why in this way Pin
Niklas L1-Feb-11 1:49
Niklas L1-Feb-11 1:49 
AnswerRe: use the member pointer via a Get function and allocate memory outside, not clear why in this way Pin
Andrew Brock1-Feb-11 2:17
Andrew Brock1-Feb-11 2:17 
Questionerror C2011: 'CMemDC' : 'class' type redefinition Pin
VCProgrammer31-Jan-11 21:25
VCProgrammer31-Jan-11 21:25 
AnswerRe: error C2011: 'CMemDC' : 'class' type redefinition Pin
Cool_Dev31-Jan-11 21:38
Cool_Dev31-Jan-11 21:38 
GeneralRe: error C2011: 'CMemDC' : 'class' type redefinition Pin
VCProgrammer31-Jan-11 21:41
VCProgrammer31-Jan-11 21:41 
GeneralRe: error C2011: 'CMemDC' : 'class' type redefinition Pin
PJ Arends1-Feb-11 18:14
professionalPJ Arends1-Feb-11 18:14 
GeneralRe: error C2011: 'CMemDC' : 'class' type redefinition Pin
Malli_S1-Feb-11 20:40
Malli_S1-Feb-11 20:40 
QuestionPreprocessor Directive Pin
pix_programmer31-Jan-11 17:34
pix_programmer31-Jan-11 17:34 
AnswerRe: Preprocessor Directive PinPopular
Andrew Brock31-Jan-11 17:48
Andrew Brock31-Jan-11 17:48 
GeneralRe: Preprocessor Directive Pin
Niklas L31-Jan-11 21:15
Niklas L31-Jan-11 21:15 
GeneralRe: Preprocessor Directive [modified] Pin
Stefan_Lang31-Jan-11 23:25
Stefan_Lang31-Jan-11 23:25 
GeneralRe: Preprocessor Directive Pin
Andrew Brock31-Jan-11 23:46
Andrew Brock31-Jan-11 23:46 
GeneralRe: Preprocessor Directive Pin
Stefan_Lang31-Jan-11 23:55
Stefan_Lang31-Jan-11 23:55 
GeneralRe: Preprocessor Directive Pin
Andrew Brock31-Jan-11 23:57
Andrew Brock31-Jan-11 23:57 
GeneralRe: Preprocessor Directive Pin
Niklas L1-Feb-11 1:50
Niklas L1-Feb-11 1:50 
GeneralRe: Preprocessor Directive Pin
Niklas L1-Feb-11 1:41
Niklas L1-Feb-11 1:41 
GeneralRe: Preprocessor Directive Pin
Stefan_Lang1-Feb-11 0:11
Stefan_Lang1-Feb-11 0:11 

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.