Re: void Gdk::Colormap::freeColors(Color& colors, int ncolors)



This is the C way of doing dynamic arrays (in C++ you are supposed to use containers):
Pass a pointer (the handle) to the first element and the number of elements
that are in the array, so you don't modify/use memory you shouldn't.

C-Example:

#include <stdio.h>

void foo(int* array, int count)
{
  int i;
  for (i = 0; i < count; i++) printf("%d\n", array[i]);
}

void bar()
{
  int myArray[5] = {5,4,3,2,1};
  foo(myArray, 5);
}

C++-Example:

#include <vector>
#include <iostream>

void foo(const std::vector<int>& array)
{
  for (std::vector<int>::const_iterator iter = array.begin();
       iter != array.end();
       iter++)
    std::cout << *iter << std::endl;
}

void bar()
{
  std::vector<int> myArray;
  for (int i=5; i > 0; i--) myArray.push_back(i);

  foo(myArray); //no size info needed
}


I hope that is clearer now.

Best regards,

DJ

>what is meant with "ncolors The number of colors in colors" at
>http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGdk_1_1Colormap.html#a6
  
> 
>
>how can one Color& stand for, let's say three colors ?
>thanks,
>            antonio
>_______________________________________________
>gtkmm-list mailing list
>gtkmm-list gnome org
>http://mail.gnome.org/mailman/listinfo/gtkmm-list
>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]