keyongtech


  keyongtech > vc.* > vc.mfc > 02/2004

 #1  
02-09-04, 03:57 PM
Henry
I'm neither an expertin C++ nor MFC programming, but the following lines of
code seems straight foward, but returns with an

error 2100: illegal indirection.

// create new CReference object
CReference *p_reference = (CReference*) new CReference;
// copy from addreference that belongs to a dialog
*p_reference = (CReference)adddia.addreference;
// sets internal integer value of p_reference., but causes a compilation
error
*p_reference->m_iID = 1;

If it makes a different, p_reference is later inserted into a COBArray

I actually managed to get round it doing adddia.addreference.m_iID = 1
before copying. But it's all a bit strange to me.

regards
H
 #2  
02-09-04, 04:24 PM
Bjarne Nielsen
See inline

"Henry" <abshhkc> skrev i en meddelelse
news:am52
> I'm neither an expertin C++ nor MFC programming, but the following lines

of
> code seems straight foward, but returns with an
>
> error 2100: illegal indirection.
>
> // create new CReference object
> CReference *p_reference = (CReference*) new CReference;

*****
It's not necessary to cast to the same type
*****

> // copy from addreference that belongs to a dialog
> *p_reference = (CReference)adddia.addreference;
> // sets internal integer value of p_reference., but causes a

compilation
> error
> *p_reference->m_iID = 1;

*****
Either call it like
*p_reference.m_iID = 1;
or
p_reference->m_iID = 1;
*****
[..]
 #3  
02-09-04, 04:28 PM
Ali R.
Which line is the error on????

Anyway, you don't need to cast your new statement the return type and the
variable are the same

CReference *p_reference = new CReference;

Now as far as the assignment goes, does your CReference class have an =
operator?

*p_reference = (CReference)adddia.addreference;

Ali R.


"Henry" <abshhkc> wrote in message news:am52
[..]
 #4  
02-09-04, 04:32 PM
Ali R.
And I missed the way you were accessing the variable inside p_reference.

either use a *p_reference.variable or p_reference->variable

Ali R.

"Ali R." <nospam> wrote in message
news:8956
[..]
 #5  
02-09-04, 05:01 PM
Paavo Helde
Henry wrote:

> I'm neither an expertin C++ nor MFC programming, but the following lines of
> code seems straight foward, but returns with an
>
> error 2100: illegal indirection.
>
> // create new CReference object
> CReference *p_reference = (CReference*) new CReference;
> // copy from addreference that belongs to a dialog
> *p_reference = (CReference)adddia.addreference;
> // sets internal integer value of p_reference., but causes a compilation
> error
> *p_reference->m_iID = 1;


-> bounds tighter than *, so you have to use parens:

(*p_reference)->m_iID = 1;

hth
Paavo
 #6  
02-09-04, 05:06 PM
Paavo Helde
Henry wrote:

> I'm neither an expertin C++ nor MFC programming, but the following lines of
> code seems straight foward, but returns with an
>
> error 2100: illegal indirection.
>
> // create new CReference object
> CReference *p_reference = (CReference*) new CReference;
> // copy from addreference that belongs to a dialog
> *p_reference = (CReference)adddia.addreference;
> // sets internal integer value of p_reference., but causes a compilation
> error
> *p_reference->m_iID = 1;


Sorry, pressed the send button too soon. Actually you have double
indirection here, but I suspect you only need one. You can write either

p_reference->m_iID = 1;

or

(*p_reference).m_iID = 1;

Paavo
 #7  
02-09-04, 05:23 PM
Dan Bloomquist
Henry wrote:
> I'm neither an expertin C++ nor MFC programming, but the following lines of
> code seems straight foward, but returns with an
>
> error 2100: illegal indirection.
>
> // create new CReference object
> CReference *p_reference = (CReference*) new CReference;


You can:
CReference *p_reference= new CReference;

if you look at it like this:
CReference* p_reference= new CReference;

you will see that p_reference is a pointer to the object.


> // copy from addreference that belongs to a dialog
> *p_reference = (CReference)adddia.addreference;


if addreference is a CReference object, you only need to:
*p_reference= adddia.addreference;

You only need to cast if CReference is a base class of addreference. It
is always safer not to cast unless you absolutely know what you intend.

> // sets internal integer value of p_reference., but causes a compilation
> error
> *p_reference->m_iID = 1;


p_reference->m_iID = 1;
or:
(*p_reference).m_iID = 1;

But:
*p_reference.m_iID = 1;

will not work. the (.) takes precedence over (*) and tries to treat
p_reference as a reference. It is not a reference to the object, you
will get an error. That is why the prins in the 'or' example above.

> If it makes a different, p_reference is later inserted into a COBArray


Not at all.

> I actually managed to get round it doing adddia.addreference.m_iID = 1
> before copying. But it's all a bit strange to me.


You need to get a handle on the difference between a pointer to
something and the something and how they are represented in C++. Your
p_reference is a pointer (*p_reference) is a reference. A reference to
an object looks just like an object.
[..]
Similar Threads
am i being thick??

my new laptop (brought today) doesnt have a SHUTDOWN button!!!! i looked at the help pages and it says that its on the little triangle button next to the lock button...but i...

Am I being thick?

Hi everyone I am not an expert on Excel but have generally managed to get roun most things but this problem has me stumped. I have 3 rows of numbers; each row preceeded by...

Am I being thick!

I posted a question to this group about 3 hours ago and can't see it has been received. It does help that the listing is in no particular order. Is something wrong your end...

Help I'm thick

Hiya, Reference to previous help message.. How do I open a CMD exe session? I can follow instructions but need them from A to Z Anyone? Thanks Barbara

im thick

i seem to have dragged the main screen of my winamp3 out of the screen completeley and now i cannot get it back.. im really new to this and i hope there is an easy solution..


All times are GMT. The time now is 01:30 PM. | Privacy Policy