954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem in defining a class with another class object as its member

I have used IT++ for half a year, which is a C++ liabrary.
Recently, I got a problem when I try to write the HEADER file for a class,
with a member which is another class object.

Here is part of my code:

class A
{
    private: 
        fixvec fv;
};


fixvec is defined in IT++, actually is renamed from Vec
by typedef. fixvec means an array of Fix type data. Vec<> is a more powerful vector template in IT++.
While Fix is a class defined in IT++, to do the fixed-point operation.

When u declare a fixvec object, it only accept parameters like

( int vec_length, fix_factory = DEFAULT_FAC);


.

Look back to my previous class definition. Iwant to define fv with any parameter I want, not only the DEFAULT_FAC.

The PROBLEM is in class definition, no parameters is allowed.

class A
{
 priveate:
  fixvec fv( length, fix_fac );
};



this cant work;

The only way seems to be my definition.

fixvec fv;


.
Then the default constructor of fixvec will be called, fv will be always with DEFAULT_FAC.

Could anybody help me, please?

I triedstatic, it can solve this problem, but still not flexible,
neither convenient.

Hope I explained clearly to u guys.
Below is the link for IT++ documentation of Fix and fixvec. u can get more.
http://itpp.sourceforge.net/current/group__fixed.html#gf4093112bbb02b7c82af656adf439499

TurboCoding
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Write a constructor for A

class A
{
   public:
      A( /* ... */ ) : fv( length, fix_fac ) {}
   private:
     fixvec fv ;
};
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

Thanks a lot !It works correctly!
Never thought of the initialization list, so foolish.
Always tried to do this in the constructor body.

Thanks again!:)

TurboCoding
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: