|
-
February 2nd, 2012, 08:11 AM
#1
Is this class set up correctly
Hi all, I am not working with C++ often so I would like your advise on the following class I created. Basically, upon creating an object of this class, the constructor should do lot's of stuff and in the end have populated various members of this class. In terms of speed and efficiency, do you think the class has been set up correctly.
I changed the original names of functions and variables into generic names, so there could be some typos. Assume that everything is working, and that whatever is not defined in the class, comes from somewhere else by #include.
Thanks.
I have the following header file:
Code:
class CreateMyObjects
{
public:
CreateMyObjects(
const HFRM &ObjectIn1,
const HFRM &ObjectIn2,
const HFRM &ObjectIn3,
std::map < std::string, std::vector < AnotherObject1 > > &myMapIn1,
Date someDate);
~CreateMyObjects();
boost::shared_ptr<AnotherObject2> myObject1;
boost::shared_ptr<AnotherObject3> myObject2;
std::map < std::string, double > myMap1;
std::map < std::string, std::map <std::string, std::map < long, double > > > myMap2;
std::vector < double > myVector1;
std::vector < double > myVector2;
private:
const HFRM &obj1_;
const HFRM &obj2_;
const HFRM &obj3_;
std::map < std::string, std::vector < AnotherObject1 > > &obj4_;
QuantLib::Date someDate_;
void function1();
void function2();
void function3();
void function4();
void function5();
};
And the corresponding code for this class is:
Code:
CreateMyObjects::CreateMyObjects(
const HFRM &ObjectIn1,
const HFRM &ObjectIn2,
const HFRM &ObjectIn3,
std::map < std::string, std::vector < AnotherObject1 > > &myMapIn1,
Date someDate)
: obj1_(ObjectIn1),
obj2_(ObjectIn2),
obj3_(ObjectIn3),
obj4_(myMapIn1),
someDate_(someDate)
{
CreateMyObjects::function1();
CreateMyObjects::function2();
CreateMyObjects::function3();
CreateMyObjects::function4();
CreateMyObjects::function5();
}
void CreateMyObjects::function1()
{
CreateMyObjects::myObject1 = createObjectFunction1(obj1_, obj2_, obj3_, someDate_);
}
void CreateMyObjects::function2()
{
CreateMyObjects::myObject2 = createObjectFunction2(obj1_, obj4_, someDate_);
}
void CreateMyObjects::function3()
{
CreateMyObjects::myObject3 = createObjectFunction3(obj2_, obj4_);
}
void CreateMyObjects::function4()
{
CreateMyObjects::myObject4 = createObjectFunction4(obj1_, obj2_);
}
void CreateMyObjects::function5()
{
CreateMyObjects::myObject5 = createObjectFunction5(obj3_, obj4);
}
In my main I use a call like:
Code:
CreateMyObjects* myObject;
myObject = new CreateMyObjects(obj1, obj2, obj3, obj4, someDate);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|