![]() |
| | #1 |
| Registered User Join Date: Jul 2009 Location: Kerala, India
Posts: 3
| Kindly see the snippet below Code: typedef int *ptr; const ptr p; Suppose if we want to make the value pointed to by p, a constant, what is to be done? Regards, thelink123 Last edited by thelink123; 07-24-2009 at 01:29 AM. Reason: Not the explantion, but the work around that is required |
| thelink123 is offline | |
| | #2 |
| Registered Luser Join Date: Jul 2005 Location: Singapore
Posts: 867
| I believe your only choice is to change the typedef or create a new typedef or not use it: Code: typedef const int *ptr; ptr p; |
| cwr is offline | |
| | #3 |
| Registered User Join Date: Jul 2009 Location: Kerala, India
Posts: 3
| Thanks cwr |
| thelink123 is offline | |
| | #4 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| It is best not to use pointers with typedefs because they generally cause confusion. Typedef the actual type, but not the pointer part of the type. Like typedef int myint; const myint* p;
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Tags |
| const, typedef |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Releasing a program - what is needed? A few Q's | ulillillia | Tech Board | 9 | 04-28-2007 12:18 AM |
| placing a clear or cls command at beginning of this program help needed | Mshock | C Programming | 15 | 05-13-2006 09:28 PM |
| Program closes prematurely. Help needed | strategicman | C++ Programming | 3 | 04-12-2006 03:09 PM |
| Please STICKY this- vital to MSVC 6 dev - BASETSD.h | Bubba | Game Programming | 11 | 03-15-2005 09:22 AM |
| Bug favour needed re: C++ Program | Nicole | C++ Programming | 2 | 12-05-2001 07:13 AM |