Jump to content
• ### What is your GameDev Story?

• Advertisement

# Derefferncing a pointer to a struct

This topic is 3650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hello All, Is derefferncing a pointer to a struct possible? My compiler doesn't seem to think so.  Vector temp1 = *ptr->v3; //ptr is a pointer to a polygon c:\tutorial\gouraud\gp\gp\main.cpp(492) : error C2440: 'initializing' : cannot convert from 'Vector *' to 'Vector' [\code] Thanks in advance. 
 0 
 Share this post Link to post Share on other sites 
 
 
 (adsbygoogle = window.adsbygoogle || []).push({}); Advertisement Telastyn    3778 Telastyn Member 3778 Posted January 22, 2009 You'll probably need some paren orientation to get the order of operations right. 0 Share this post Link to post Share on other sites Aardvajk    13212 Aardvajk Member 13212 Posted January 22, 2009 Quote:Original post by DarkMatter2008Vector temp1 = *ptr->v3; //ptr is a pointer to a polygonWhy are you dereferencing (*) the pointer? Assuming:struct Poly{ Vector v;};void f(Poly *ptr){ Vector temp1=ptr->v;}would be fine. ptr->v is like a shortcut to (*ptr).v so no dereferencing is necessary.You would only need the asterisk if you were dealing with a pointer-to-pointer-to Poly:void f(Poly **ptr){ Vector temp1=(*ptr)->v; // note parens as per Telastyn's comment above} 0 Share this post Link to post Share on other sites DarkMatter2008    123 DarkMatter2008 Member 123 Posted January 22, 2009 This is more like what it is;struct Vector{//Vector information here}struct Poly{ Vector *v;};void f(Poly *ptr){ Vector temp1=ptr->v; // Needs to be derefferenced so that the Vector can be copied.}I'm trying to dereffernce the struct pointer in order to copy the struct. 0 Share this post Link to post Share on other sites Telastyn    3778 Telastyn Member 3778 Posted January 22, 2009 (*(ptr->v)); (iirc) 0 Share this post Link to post Share on other sites DarkMatter2008    123 DarkMatter2008 Member 123 Posted January 22, 2009 Quote:Original post by Telastyn(*(ptr->v)); (iirc)hmmm, thouse extra set of brackets seem to have done the trick.I tried this before*(ptr->v)with out the outer ones but it didn't work.anyways, thank you very much Telastyn :) 0 Share this post Link to post Share on other sites 
 Sign in to follow this   Followers 0 
 Go To Topic Listing General and Gameplay Programming Advertisement 
 Advertisement What is your GameDev Story? In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us. (You must login to your GameDev.net account.) Share My Story Popular Tags 2D 3D Advice Algorithm C# C++ Character Concept Design DX12 GameMaker Gameplay General Graphics Mobile Music OpenGL Open Source Optimization PC Pixel Unity Unreal VR Vulkan Popular Now 24 Anyone who wants to write a little game engine? By DaTueOwnerStarted Friday at 09:12 PM 15 OpenGL Textures, Pixel Alignment And Texture Mistakes. What Am I Doing Wrong? By babaliarisStarted Friday at 06:34 PM 10 Managing pointers upon object destruction in C++ By too_many_starsStarted Friday at 08:21 AM 10 A Functional Impass - Advise me on how to proceed? (C#) By A4LStarted Friday at 03:32 AM 11 MMORPG Brilliant Game Idea. By Tara LouiseStarted Thursday at 12:03 AM Advertisement Forum Statistics Total Topics 634098 Total Posts 3015521 GameDev.net GameDev.net Articles GameDev.net Event Coverage GameDev.net Forums GameDev.net Blogs GameDev.net Gallery GameDev.net News GameDev.net Projects GDNet Chat All Activity Search In Everywhere This Forum This Topic More options... Find results that contain... All of my search term words Any of my search term words Find results in... Content titles and body Content titles only Home Forums Programming General and Gameplay Programming Derefferncing a pointer to a struct 
 
 
 × Existing user? Sign In Sign Up Browse Back Articles & Tutorials Back All Categories Audio Business Game Design Industry Programming Visual Arts Columns Back GameDev Unboxed Event Coverage Back All Events Game Developers Conference Power Up Digital Games Conference GameDev.Market Links News Podcasts Back All Podcasts Game Dev Loadout Archive Community Back Beginners Back Beginners Group Beginners Forum Beginners Resources Blogs Calendar Chat Forums Back All Forums Audio Business Game Design Programming Visual Arts Community GameDev Challenges Affiliates Topical Workshops Gallery Groups Back For Beginners GameDev Challenges All Groups Projects Back All Projects Games Game Assets Game Mods Developer Tools Store Forums Back All Forums For Beginners Audio Back Music and Sound FX Games Career Development Business Back Games Career Development Production and Management Games Business and Law Game Design Back Game Design and Theory Writing for Games Programming Back Artificial Intelligence Engines and Middleware General and Gameplay Programming Graphics and GPU Programming Math and Physics Networking and Multiplayer Visual Arts Back 2D and 3D Art Critique and Feedback Community Back GameDev Challenges GDNet Lounge GDNet Comments, Suggestions, and Ideas Coding Horrors Your Announcements Hobby Project Classifieds Indie Showcase Affiliates Back NeHe Productions AngelCode Topical Workshops Careers Back Contractors Hobby Projects Game Jobs Back Browse on GameDev.Jobs Post a Job Members Back Subscriptions Chat Guidelines Leaderboard Online Users Awards Search Back All Activity My Activity Streams Back Latest Topics Featured Blogs Search Important Information By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.   I accept GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry. Sign me up! 
 $('body').click(function (e) { var container =$("#pagecontainer"); if (($(e.target).parent().prop('nodeName') == 'BODY') && (container.has(e.target).length === 0) && (e.button == 0) && (!$(e.target).hasClass('ipsDialog'))) { window.open('https://ad.doubleclick.net/ddm/trackclk/N129002.1825GAMEDEV.NET/B11085475.236262913;dc_trk_aid=433791501;dc_trk_cid=90245747;dc_lat=;dc_rdid=;tag_for_child_directed_treatment=;tfua='); ga('send','event','Advertisement','Click','3q_fb_gamedev_skin_2019_1'); } }); $(document).ready(function() { setInterval(function() { window.googletag.pubads().refresh(); }, 30000); });$(document).ready(function() { if (ipsSettings.memberID > 0) { ga('send','event','User','View','Member'); } else { ga('send','event','User','View','Guest'); } });