What's wrong with this?

This is a discussion on What's wrong with this? within the C++ Programming forums, part of the General Programming Boards category; I am trying to allocate a dynamic array of pointers to classes. Therefore I create a pointer to a pointer ...

  1. #1
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368

    What's wrong with this?

    I am trying to allocate a dynamic array of pointers to classes. Therefore I create a pointer to a pointer and allocate the array to it with the new operator, thus:

    inPort **input;
    .
    .
    .
    input = new (*inPort [inputs]);

    But the compiler comes up with three errors:
    'cannot convert int * * to inPort * *'
    'type name expected'
    'statement missing ; '

    All three errors are for the same line.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    ..this might help.



    Code:
                  //This creates an array of pointers to input objects
                  //access example     i[ n ]->MyFunction();
                   input **i;
    
    	i = new input*[10];
    	
    	for(int j = 0; j < 10; j++)
    	{
    		i[j] = new input; 
    	}
    
                  //This on the other hand creates an array of objects
                 //access example is i[ n ].MyFunction();
                 //this is what you might want
                 //I would use the ** only in two ocassions
                 //... 1. to create a two dimensional array
                 //... 2. as a parameter in a function to modify say the root
                 //... of a tree... but with C++ the         obj &myObj eliminates the need for the 2nd case
                 input* i;
    
                  i = new input[10];
    zMan

  3. #3
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    Man, THANK YOU!
    I can't believe it was such a simple mistake. I had the star in the wrong place. I was tearing my hair out over that, too.

    Thanks!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

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