Pointer Problems

This is a discussion on Pointer Problems within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a problem with a certain part of code I'm currently working on. I have a vector sorting ...

  1. #1
    Unregistered
    Guest

    Question Pointer Problems

    Hi,

    I have a problem with a certain part of code I'm currently working on.

    I have a vector sorting a set of HObjects (self defined class).

    I want to create a pointer to a HObject being popped from the vector.

    Code:
    vector<HObjects> set;
    
    fillvector(set);
    
    HObject *new;
    
    new = set.pop_back();  //***
    However, (***) is giving me this error:
    "void value not ignored as it ought to be"

    Is there something wrong with the way I'm doing this?
    Thank You.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    pop_back does not return a value for one, you have to get the values beforehand. Also, you are popping it so the object should be lost, the pointer would mean nothing. You should probably be storing a vector of pointers instead. Something like this:
    Code:
    vector<HObjects*> set;
    fillvector(set); //puts dyn allocated instances in it
    
    HObject *new;
    
    new = set[set.size()-1];
    set.pop_back();
    try that out

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    just realized, you used "new" as a variable name too. naughty naughty.

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Yes, new is a reserved keyword. Your IDE should have changed its color for you. (Assuming you use that feature) As Hershlag said, you cannot use reserved keywords for variable names.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with passing an array of structures by pointer
    By raptor1770 in forum C Programming
    Replies: 9
    Last Post: 11-29-2008, 10:01 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. base class pointer problems
    By ... in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2003, 10:27 PM

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