-
May 12th, 2010, 10:53 AM
#1
need help assigning one structure to another using pointers
Hi,
i have two pointer to structures named *currMB and *PrevMB and i want to assign PrevMB into currMB.
will the C++ code below work.
struct Macroblock *currMB;
struct Macroblock *PrevMB;
*currMB= & PrevMB;
and if i want to average these two structures and put the output in currMB.
then can i write
currMB = (currMB+PrevMB)/2;
-
May 12th, 2010, 10:59 AM
#2
Re: need help assigning one structure to another using pointers
No, it will fail (crash)
You must instantiate Macroblock objects, not just the pointers that point to none/nowhere.
Victor Nijegorodov
-
May 12th, 2010, 11:28 AM
#3
Re: need help assigning one structure to another using pointers
Originally Posted by naeem561
Hi,
i have two pointer to structures named *currMB and *PrevMB and i want to assign PrevMB into currMB.
will the C++ code below work.
struct Macroblock *currMB;
struct Macroblock *PrevMB;
*currMB= & PrevMB;
and if i want to average these two structures and put the output in currMB.
then can i write
currMB = (currMB+PrevMB)/2;
How do you average a struct? Conceptually that doesn't make much sense.
-
May 12th, 2010, 11:36 AM
#4
Re: need help assigning one structure to another using pointers
As victor said, they are only pointers currently pointing to nothing.
Code:
struct Macroblock *currMB = new Macroblock;
struct Macroblock *PrevMB = new Macroblock;
Now they point to a Macroblock (don't forget to delete them as soon as you are done with them).
Code:
currMB = (currMB+PrevMB)/2;
To do this you need to implement your own = + and / operator. Assuming that your struct contains some numbers you can average.
-
May 12th, 2010, 12:27 PM
#5
Re: need help assigning one structure to another using pointers
Well.. the program will not compile itself!
You cannot add two pointers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|