Book a Demo

Author Topic: C++ code generation  (Read 4876 times)

timhawkins

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
  • If a man says something and a woman is not around to hear him, is he still wrong?
    • View Profile
C++ code generation
« on: June 25, 2002, 03:04:40 am »
EA does not seem to ge generating C++ code the way I would have expected it to.

I have created a simple class with an initialised string, and asked to produce Get/Set members

The code generated is :

///////////////////////////////////////////////////////////
//
//  TestClass.cpp
//  Implementation of the Class TestClass
//  Generated by Enterprise Architect
//  Created on:      25-Jun-2002 10:49:14
//  Original author:
//  
///////////////////////////////////////////////////////////
//  Modification history:
//  
//
///////////////////////////////////////////////////////////

#include "TestClass.h"

TestClass::TestClass(){

}


TestClass::~TestClass(){

}


string TestClass::GetTestString(){

}


void TestClass::SetTestString(string newVal){

}


///////////////////////////////////////////////////////////
//
//  TestClass.h
//  Implementation of the Class TestClass
//  Generated by Enterprise Architect
//  Created on:      25-Jun-2002 10:49:14
//  Original author:
//  
///////////////////////////////////////////////////////////
//  Modification history:
//  
//
///////////////////////////////////////////////////////////


#if !defined(TestClass_F978D2C3_53D3_4392_926F_F001AAF35019__INCLUDED_)
#define TestClass_F978D2C3_53D3_4392_926F_F001AAF35019__INCLUDED_



class TestClass
{

public:
     TestClass();
     virtual ~TestClass();

public:
     string TestString;
     string GetTestString();
     void SetTestString(string newVal);
};

#endif // !defined(TestClass_F978D2C3_53D3_4392_926F_F001AAF35019__INCLUDED_)

However I would have expected it to generate: ========

///////////////////////////////////////////////////////////
//
//  TestClass.cpp
//  Implementation of the Class TestClass
//  Generated by Enterprise Architect
//  Created on:      25-Jun-2002 10:49:14
//  Original author:
//  
///////////////////////////////////////////////////////////
//  Modification history:
//  
//
///////////////////////////////////////////////////////////

#include "TestClass.h"

TestClass::TestClass(){
        TestString = "Initialiser";
}


TestClass::~TestClass(){

}


string TestClass::GetTestString(){
        return TestString;
}


void TestClass::SetTestString(string newVal){
        TestString = newVal;
}


Ie the GetSet members dont actualy Get or Set the property they are refering to and the constructor does not initialise variables if there is an initialiser specified.

It would also be nice to be able to specify a set of standard methods for each class, ie always generate a copy constructor, an assignment operator and a set of comparison operators


Rafael Gonzalez

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: C++ code generation
« Reply #1 on: June 25, 2002, 08:51:19 am »
In my humble opinion, it is betterto leave these methods empty.
You may wish to write some checking code before getting or setting an attribute.

Otherwise, I see no difference in declaring the attribute as public.

Rafael


timhawkins

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
  • If a man says something and a woman is not around to hear him, is he still wrong?
    • View Profile
Re: C++ code generation
« Reply #2 on: June 26, 2002, 02:27:38 am »
If you want to add checking code then thats no problem,

but it should generate the access code.

It just takes all the grunt work out of building interfaces.

I am however concerned that the initialisers are not being used to initialise the variables.