×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

come'on in

1) you should have a header file and implementation file for each class.
then cross compile them together.
2) parameterized manipulators are just those function like statements
inserted into the iostreams:
cout << setprecision(3) <<2.3445566<<endl;
will output 2.344
This is analogous to the printf("%.3f", 2.3445566) in C
3) Because when you delete an object of a derived class, you want to
invoke the destructor of the derived class rather than that of the parent
class, even if you are deleting the object
through a pointer to the parent class.
4) Return by reference means that you have such declaration:
int& myfunc(){...}
it prevents the compiler from making a copy of the object you
have returned.
This is dangerous for local objects because you may have had the
object destroyed on the stack. The most common use of return by
reference is to return *this.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / could anyone help me on C++ question?
    1.How would you set up a multiple file application that had five classes?
    2.What is meant by a parameterized manipulator?
    3.Why should you write a virtual destructor?
    4.What does "return by reference" mean, and when can you return a local variable by reference?
    in fact ,I am not clear what 1 and 2 means?
    and 4 means pass function's parameter by reference?????
    • Please help me,please
      • come'on in
        1) you should have a header file and implementation file for each class.
        then cross compile them together.
        2) parameterized manipulators are just those function like statements
        inserted into the iostreams:
        cout << setprecision(3) <<2.3445566<<endl;
        will output 2.344
        This is analogous to the printf("%.3f", 2.3445566) in C
        3) Because when you delete an object of a derived class, you want to
        invoke the destructor of the derived class rather than that of the parent
        class, even if you are deleting the object
        through a pointer to the parent class.
        4) Return by reference means that you have such declaration:
        int& myfunc(){...}
        it prevents the compiler from making a copy of the object you
        have returned.
        This is dangerous for local objects because you may have had the
        object destroyed on the stack. The most common use of return by
        reference is to return *this.
        • numnum is a c++ expert. i salute u.
          • thanks,killer, we should try to solve people's problems when jabber is not around, shouldn't we :)
        • u r so helpful.Thanks. Could you explain more detail about first question?Thanks again
          • one .h file and one .cc file for each class, so you will end up with 5 .h files and 5 .cc files. sometimes, people also add a .x file for each class to provide externel interface, in this case, .h file is used for internal implementaion.
            • and u could add "#pragma once" at the head of the header file which is included more than once. it tells the compiler to compile it only once.
              • good idea, but #progma directive is usually platform dependant. I usually add the following in each header file: #ifdef _FILE_H_ #define _FILE_H_ .... #endif to prevent multiple inclusion of the same header file
    • Although having used C++ for years, I suddenly find I don't understand your terms in English :-( Who can recommend me any books on C++ in English?
      • Thinking in C++, u can DL it.
        • from where?
          • www.mindview.net
      • effective C++, more effective C++ , and C++ Programming Language by bjarne Stroustrup( I like the old version (thin, brownish cover, co-authored with Margret ) better than new version(thick, blue cover))
        • Many thanks :-)