O Código é bem simples! Eu tenho duas classes aluno.h e diciplina.h e preciso manter uma dependência circular entre elas!
quando estou em aluno.h eu consigo criar um atributo da classe diciplina usar new, construtor,sets e gets. Mas quando faço alcontrario eu consigo criar e setar como 0 mas n consigo dar um new e usar :/
[Error] forward declaration of 'class diciplina::aluno' e
[Error] invalid use of incomplete type 'class diciplina::aluno'
Deis de já grato!
#ifndef DICIPLINA_H
#define DICIPLINA_H
#include <string>
using namespace std;
#include "aluno.h"
#define MAX 20
class aluno;
class diciplina{
public:
class aluno;
diciplina(string codDic, string descricaoDisc){
this->codDic = codDic;
this->descricaoDisc = descricaoDisc;
for(int i = 0; i<20; i++) // Inicializa com tudo 0
dA[i] = 0;
}
~diciplina(){
delete[]dA;
}
bool matricula(aluno **al,int id){
for(int i = 0; i<10; i++)
if(dA[i] == 0){
dA[i] = new aluno("Fulano","09834534","Computer Science"); // ESSA LINHA QUE DA ERRO
return true;
system("pause");
}
return false;
}
private:
string codDic;
string descricaoDisc;
aluno *dA[MAX];
};
#endif
#ifndef ALUNO_H
#define ALUNO_H
#include <string>
#include <iostream>
#include "diciplina.h"
using namespace std;
class diciplina; // declaracação forward
class aluno
{
public:
aluno(string nome, string cpf, string curso){
this->nome = nome;
this->cpf = cpf;
this->curso = curso;
for(int i = 0; i<10; i++)
alunoDiciplinas[i] = 0;
}
~aluno(){
delete[] alunoDiciplinas;
}
bool matricula(diciplina **dic,int id){
for(int i = 0; i<10; i++)
if(alunoDiciplinas[i] == 0){
alunoDiciplinas[i] = new diciplina(dic[id]->getCod(),dic[id]- >getDiciplina()); // MAS AQUI NÃO DA ERRO !!
return true;
}
return false;
}
private:
string nome, cpf, curso;
diciplina *alunoDiciplinas[10];
};
#endif