Greetings from Portugal to everyone.

I'm building a project to a course in my university and i've stucked in some compiling error given by NetBeans and g++ in my dynamic array implementation. Glad if someone could give a hand to this.

Here is the code

#pragma once

#include <iostream>
#include <string>

#include "Edificio.h"
#include "Camiao.h"

using namespace std;

class Armazem:public Edificio
    Camiao **vecCamiao[];
    int numCam, tamCam;
    Armazem(int c, string d);
    Armazem(const Armazem &a);
    virtual ~Armazem();
    /*Armazem& operator =(const Armazem& p_arm);
    bool operator ==(const Armazem& p_arm) const;
    bool operator >(const Armazem& p_arm) const;
    void escrever(ostream& out) const;*/
    void insereCamiao(Camiao *vC);
    void listaCamiao(Camiao *vc);

Armazem::Armazem(int c, string d):Edificio(c,d)

   tamCam = 50;
   numCam = 0;
   vecCamiao = new Camiao*[tamCam];

void Armazem::insereCamiao(Camiao* vC)

    if(numCam == tamCam)
        Camiao ** nVec = new Camiao*[2*tamCam];
        tamCam = tamCam*2;
        for(int i=0;i<numCam;i++)
            vecCamiao = nVec;
void Armazem::listaCamiao(Camiao* vC)
    for(int i=0; i<numCam; i++)

And the error code:

g++.exe    -c -g -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
Armazem.h: In constructor `Armazem::Armazem(int, std::string)':
In file included from main.cpp:7:
Armazem.h:35: error: incompatible types in assignment of `Camiao**' to `Camiao**[0u]'
Armazem.h: In member function `void Armazem::insereCamiao(Camiao*)':
Armazem.h:49: error: cannot convert `Camiao**' to `Camiao*' in assignment
Armazem.h:50: error: incompatible types in assignment of `Camiao**' to `Camiao**[0u]'
Armazem.h:51: error: cannot convert `Camiao*' to `Camiao**' in assignment
make[2]: Leaving directory `/cygdrive/c/Users/João/Documents/NetBeansProjects/TEsinf'
make[1]: Leaving directory `/cygdrive/c/Users/João/Documents/NetBeansProjects/TEsinf'
make[2]: *** [build/Debug/Cygwin_4.x-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)

Thank you in advance for your time responding to this tread.

It appears your trying to create a 2-dimensional array. The problem is, a pointer for a 2-Dimensional array has 2-levels of indirection, but you are attempting to create a pointer with 3-levels of indirection.

Try taking the [Square Braces] off your declaration of vecCamiao...

Edited 6 Years Ago by Fbody: n/a

Thanks for your replies.

Fbody, thank you. It was my fault since I never looked at that declaration with its due attention. That surely did the trick ;)

Gerard, that declaration was the error, but I was trying to create a dynamic array of pointers to pointers.

Thank you both, once again

--- Edited Double Post---

Edited 6 Years Ago by fantasma: n/a

Pá não tenho tempo para ir aos profs tenho de fazer desta maneira (que se calhar até é a melhor) :P

This article has been dead for over six months. Start a new discussion instead.