Pointers

This is a discussion on Pointers within the C++ Programming forums, part of the General Programming Boards category; Well, i'm new but here's my problem Code: __int16 PointerControl::ReadShort() { __int16 *data; data = pointer; pointer += sizeof(data); return ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    1

    Pointers

    Well, i'm new but here's my problem

    Code:
    __int16 PointerControl::ReadShort()
    {
    	__int16 *data;
    	data = pointer;
    	pointer += sizeof(data);
    	return *data;
    }
    pointer is a int, and i want to return the short value at the address of pointer.

    but this ^^ doesn't work, any suggestions?

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    try

    data = &pointer;

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Unless pointer is global and decalred somewhere else, it's not declared. You need to allocate space for it. Also, I'm not too sure what you're trying to do here. Either you need to rename your variables, or reorganize the equations. Right now it looks like "data" is a pointer and "pointer" is some data. And I don't think you need sizeof(data). pointer++ would work because C/C++ automatically scales the increments to the size of the variable.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is dynamic allocation.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21