help with pointers

This is a discussion on help with pointers within the C++ Programming forums, part of the General Programming Boards category; hi I need some help as to why this won't work Code: class CD { struct node { int nTracks; ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    5

    help with pointers

    hi I need some help as to why this won't work
    Code:
    class CD
    {
    	struct node
    	{
    		int nTracks;
    		string cdName;
    		node *next;
    	};
    
    	int nVolume;
    	bool bPower;
    	node *start;	
    	start = new node; //<- trouble here
    	start->next = NULL;
    I get the error C2258: illegal pure syntax, must be '= 0'
    at the start = new node;

    any idea as to what I am doing wrong?

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    Memory for datamembers is allocated when objects are created

    Hi

    You are trying to allocate memory for a datamember within a class.... instead try allocating the same when objects of that class are cerated.


    class CD
    {
    struct node
    {
    int nTracks;
    string cdName;
    node *next;
    };

    int nVolume;
    bool bPower;
    node *start;


    public:
    CD()
    {
    start = new node;
    start->next = NULL;
    }
    ~CD()
    {
    delete start;
    }

    };
    Last edited by shiv_tech_quest; 01-10-2003 at 05:58 AM.
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    5
    thanks shiv_tech_quest that seems to have worked

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