Re: [Dev-C++] (no subject)



Hello,

      I will hazzard a guess that you are getting the address of the
function rather than the value, but I did notice two things that you
may want to review.  The first is that you don't beed the friend
declarations since you are using a public method.  If you want to
grant special permission to the function then you can access the
'protected' "amount" directly but if you don't need special permission
(which you don't when you use the getter function) you can drop the
friend.

The big question is that is 'jme' in "jme::Money"  are you working
inside a separate class or namespace?  The Money class in main doesn't
seem to be referenced as such so it's not clear why it's there.  It's
possible that if you have been making many changes and that's a hold
over than you are really referencing a different item?

Hope this helps,
Robert



On 6/30/05, jalkadir gosonic ca <jalkadir gosonic ca> wrote:
> In my class, when I use the "getter" to display the value I get the right
> output, but when I try using the overloaded extractor operator (<<) I get
> some hex value displayed. Here is some of the code:
> --- snip
> Main.cpp
> int main() {
>    Money money("12.21");
> 
>    std::cout << "Value is: " << money.getAmount() << std::endl; // 12.21
>    std::cout << "Value is: " << money << std::endl; // hex value????
>    return 0;
> }
> 
> 
> 
> The class goes like this:
> ---snip
> Money.hpp
> class Money {
>  protected:
>    float amount;    //!< This variable holds the numerical value
>  public:
>    //! Constor
>    Money(const std::string&);
> 
>    //!Copy constructor
>    Money( const Money& );
> 
>    //!Destructor
>    ~Money() { std::cout << amount << std::endl;} //<<=== 12.21
> 
>    // Setters
>    ...
>    // Getters
>    const float getAmount() const;
> 
>    // Overloaded operators
>    .....
>    friend std::ostream& operator<<( std::ostream&, const jme::Money& );
>    friend std::istream& operator>>( std::istream&, jme::Money& );
>    ....
> } ; //Money
> 
> 
> 
> and the code looks like this
> --- snip
> jme::Money::Money( const std::string& x){
>     this->setAmount(x); // this metho converts the std::string to a float
> }
> const float jme::Money::getAmount() const {
>     return this->amount;
> }
> std::ostream&
> jme::operator<<( std::ostream& os, const jme::Money& obj ) {
>     os << obj.getAmount(); //<<==== 0x4b1120
>     return os;
> }
> ----- end of snip
> As you can see when using the member method getAmount() the value
> displayed is in the right format, however the extractor operator is not
> doing the job I thought it would.
> 
> Can anybody tell me what I am doing wrong?
> 
> TIA
> 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&opclick
> _______________________________________________
> Dev-cpp-users mailing list
> Dev-cpp-users lists sourceforge net
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]