我遇到了一个我无法解决的C++程序中的问题。 我想传递一个对象作为另一个的构造参数,但我无法弄清楚如何做到这一点。对象成员的问题
我的主要工作是创建一个模拟对象。在模拟中,我创建了两个对象平面和模型。事情是,我想通过模型化对象中的平面对象。
我的第一个对象是模拟。
#include "Simulation.h"
#include "Modelisation.h"
#include "Planete.h"
Planete *Obj;
Modelisation *Model;
Simulation::Simulation (int argc, char **argv)
{
Obj = new Planete ("Terre", (5.98*pow(10.0,24.0)), 6378.137, 0, 0, 0);
Model = new Modelisation (argc, argv,"Modelisation",1600 ,1004, 306, 0);
};
Simulation::~Simulation()
{
delete Obj;
delete Model;
};
Modelisation.h
class Modelisation
{
private:
int hauteur, largeur, x, y;
int fenetre;
//Planete ClonePlanete
public:
Modelisation (int argc, char **argv, char[], int, int, int, int);
~Modelisation();
static void Dessiner();
static void Redessiner (int, int);
void InitCallBack();
};
Modelisation.cpp
#include "stdafx.h"
#include "Modelisation.h"
#include "Camera.h"
#include "Planete.h"
Camera *camera;
Modelisation::Modelisation (int argc, char **argv, char nomFenetre [] ,int hauteur, int largeur, int x, int y)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE);
glutInitWindowSize (hauteur, largeur);
glutInitWindowPosition (x, y);
fenetre = glutCreateWindow (nomFenetre);
camera = new Camera;
// Planete ClonePlanete = new Planete(planete); // Basicaly that's what i'm trying to do
};
Modelisation::~Modelisation()
{
delete camera;
};
Planete.h
class Planete
{
private:
std::string nom;
double masse;
double diametre;
struct position { double x, y, z;};
double x,y,z;
public:
Planete (std::string nom, double masse, double diametre, double x, double y, double z);
Planete (const Planete &);
~Planete();
};
感谢您的帮助,将不胜感激!
这并不完全清楚你在这里问什么。究竟是哪条线给你带来麻烦? – 2011-04-15 15:07:44
您可以尝试发布最简单的代码示例,该示例不会编译/工作,可以证明您的问题。我并不是说没有人会阅读你的代码,但这会让它变得更加困难。 – briantyler 2011-04-15 15:08:24
你说得对,那就是我要做的。 – Athanase 2011-04-15 15:09:51