0
   #include<iostream.h>
   class man
  {
   public:
   void money()
   {
     for(int i=0;i<5;i++)
     cout<<i;
   }

   };

   void main()
   {

      man m;
      m.money();

    }

When this is compiled a warning is shown as-"Functions containing for are not expanded inline". Why is it so?

JBentley
  • 6,099
  • 5
  • 37
  • 72
  • 1
    What compiler with what flags? – Shoe Jan 14 '14 at 18:37
  • What compiler are you using? – Oliver Charlesworth Jan 14 '14 at 18:37
  • 5
    Because it looks like you're using TurboC++ which is more than 20 years old. – Captain Obvlious Jan 14 '14 at 18:38
  • I'm using turbo c++ IDE. That's all I know. –  Jan 14 '14 at 18:38
  • 1
    Also `void main` is a big nono. Also you are using `cout` instead of `std::cout`. Also `` might be a problem. – Shoe Jan 14 '14 at 18:38
  • @Jefffrey TurboC++ does not support the std namespace (if it supports namespaces at all) and `void main()` is perfectly acceptable with that antiquated compiler. – Captain Obvlious Jan 14 '14 at 18:39
  • I'm doing introductory computer science course in my school and this is how we are asked to write programs, using void main(),cout etc. I don't know about std:cout. –  Jan 14 '14 at 18:40
  • @CaptainObvlious, I'm scared. – Shoe Jan 14 '14 at 18:40
  • 1
    Wow I just realized the last time I used Turbo C++ was my last year of High school, and yes that was almost 20 years ago. Now I feel old :P – Jason Sperske Jan 14 '14 at 18:40
  • 6
    @RajathKrishnaR Your _school_ is doing you a disservice teaching you programming with such an out-dated piece of compiler technology. You should request a refund. – Captain Obvlious Jan 14 '14 at 18:41
  • @CaptainObvlious But, they say knowing the basics is important and so is basic programming languages like c++.Is it really necessary to study c++ to start on with computer science? –  Jan 14 '14 at 18:43
  • 4
    [Don't use Turbo C++](http://stackoverflow.com/questions/2513133/cannot-run-c-graphics-programs/3435105#3435105) (And yes, C++ is a very good place to start on Computer Science. But Turbo C++, which is around 20 years old, is no longer relevant, and should not be taught.) – abelenky Jan 14 '14 at 18:44
  • @RajathKrishnaR Learning c++ will help you, learning c++ with a broken compiler will hurt you. – Dan Jan 14 '14 at 18:45
  • @abelenky But, that is what we are told to use in high school. No other go. –  Jan 14 '14 at 18:45
  • @RajathKrishnaR There are free compilers that are up to date with the standards. You may want to point that out to your teacher. Roughly half of what you learn on a compiler that outdated will be irrelevant as soon as you learn it. – Zac Howland Jan 14 '14 at 19:04
  • @Jefffrey Early C++ provided .h versions of headers which did NOT use a namespace, as a bridge between C and C++. It's a REALLY, really bad thing to be teaching people. – kfsone Jan 14 '14 at 19:07
  • @RajathKrishnaR There are four standard editions of C++, the first is dated 1998 (http://en.wikipedia.org/wiki/C%2B%2B#Standardization). Your compiler was written in 1993. The language you will learn by using it is as far removed from any modern version of C++ as either C or Objective-C. Using it to learn C would be much more beneficial than using it to learn C++. C has also changed a lot, but was mature at the time Turbo-C was actively being developed – kfsone Jan 14 '14 at 19:30

2 Answers2

2

Functions defined in a class considered by default as having the inline function specifier even when you do not explicitly specify it. However, not all functions can be inlined by the compiler. The compiler tells you about this.

Take into account that if you use a modern compiler, it will not compile the code. The identifier cout will be undeclared because you did not specify its namespace, and the main function shall have return type int.

Also, I would declare the function money with a const qualifier:

void money() const;
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

TurboC++ is a very old compiler and by today's standards is quite deficient when compared to standardized C++. When you include the definition of a member function inside the definition of a class the function is implicitly inlined. You receive the warning because TurboC++ does not have the ability to inline functions containing certain language constructs. In this case it's a for loop that the compiler is unable to inline. This is not the case with more recent commonly used compilers such as GCC and MSVC as they are able to inline the functions.

Although I normally do not recommend ignoring warnings generated by a tool chain I think it's completely justified in this case. Ignore it and move on.

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74