Pessoal,

Estou tendo algumas dificuldades pra dominar os ponteiros, rs
Estou usando o builder 6 e quando rodo o programa abaixo da o seguinte erro:

Project projetc1.exe raised exception class EAccessViolation with message 'Access violation at addres 01193e78 in module 'BorLndMM.DLL' Write of addres 0000004. Process stopped. Use Step or Run to continue.


Alguém tem alguma ideia do que pode ser?


Obrigado,

Marcelo Gomes


Código :
 
class Vogel{
  private:
    int **Custo;
    int ColunaSize, LinhaSize;
  public:
    Vogel();
    Vogel(int Coluna, int Linha);
    void fim(int **Custo);
    void PutCusto(int Coluna, int Linha, int Custo); // Receber os valores
    void Calcular(); // Gerenciar a ordem dos calculos
    int Menor(int MaiorQue, int *vetor, int vetorSize);
    int MenorPosicao(int MaiorQue, int *vetor, int vetorSize);
 
};
 
 
 
//---------------------------------------------------------------------------
 
 
#pragma hdrstop
 
#include "Vogel.h"
#include <vcl.h>
 
#include <exception>
#include <iostream>
 
 
 
//---------------------------------------------------------------------------
// Coluna e linha
 
Vogel::Vogel(int Coluna, int Linha){
  int x,y;
 
   try {
      Custo = new int*[Coluna];        // Aloca as Coluns
      for(int j = 0; j < Coluna; j++)
          Custo[j] = new int[Linha];  // Aloca as linhas
   }
   catch (std::bad_alloc) {  // ENTER THIS BLOCK ONLY IF bad_alloc IS THROWN.
      exit(-1);
  }
  ColunaSize=Coluna;
  LinhaSize=Linha;
 
 
  for(x=0;x<Coluna;x++)
    for(y=0;y<Linha;y++)
 
      this->Custo[x][y]=0;
}
 
void Vogel::fim(int **Custo){
   for (int i = 0; i < 4;  i++)
       delete[] Custo[i];                 // Delete as Colunas
 
   delete[] Custo;                        // Deleta as linhas
}
 
Vogel::Vogel(){
  int x,y;
  for(x=0;x<4;x++);
    for(y=0;y<4;y++);
      Custo[x][y]=0;
  ColunaSize = 4;
  LinhaSize = 4;
}
 
void Vogel::PutCusto(int Coluna, int Linha, int Custo){
  this->Custo[Coluna][Linha]=Custo;
}
 
void Vogel::Calcular(){
  int *Coluna, *ColunaSegunda;
  int *VetTmp;
  int Col, Lin;
 
 
  Coluna = new int [ColunaSize];
  VetTmp = new int [ColunaSize];
  ColunaSegunda = new int [ColunaSize];
 
////////////////////////////////////////////////
// Cria o vetor com o menor numero das colunas//
////////////////////////////////////////////////
 
  for(Col=0;Col<ColunaSize;Col++){
    for(Lin=0;Lin<LinhaSize;Lin++)
      VetTmp[Lin]=Custo[Col][Lin];
    Coluna[Lin]=(Menor(-1,VetTmp,ColunaSize));
    ColunaSegunda[Lin]=(Menor(Coluna[Lin],VetTmp,ColunaSize));
    ShowMessage(ColunaSegunda[Lin]);
  }
 
//Da o erro quando esta executando o codigo acima
////////////////////////////////////////////////
 
 
 
 
 
 
 
 
 
  delete[] VetTmp;
  delete[] Coluna;
 
 
 
 
 
  fim(Custo);
 
}
 
int Vogel::Menor(int MaiorQue, int *vetor, int vetorSize){
  return vetor[MenorPosicao(MaiorQue,vetor,vetorSize)];
}
int Vogel::MenorPosicao(int MaiorQue, int *vetor, int vetorSize){
  int x;
  int Menor;
 
  if(vetor[0]==-1) // Verifica se o vetor esta disponivel
    return -1;
  else{
    Menor=-1;
    for(x=1;x<vetorSize;x++)    // Gera um valor inicial
      if(vetor[x]>MaiorQue)
        Menor=x;
    if(Menor==-1)
      return -1; // se não existe no vetor um valor menor que o maior
    else{
      for(x=1;x<vetorSize;x++)
        if(vetor[x]>MaiorQue)
          if(vetor[x]<vetor[Menor])
            Menor=x;
    return Menor;
    }
  }
}
 
 
#pragma package(smart_init)