You are here:

C++/Doubt about inline function

Advertisement


Question
Sir,
today i was working in inline function and i use the for loop in that function but here it's not working. I am working in Visual Basic C++ 0.6
The program is as follows:-
#include<iostream>
#include<iomanip>
using namespace std;
class Pattern
{
public:
  int i;
  int j;
  int k;
  Pattern()
  {
     i = 0;
     j = 0;
     k = 1;
  }
  inline void output()
  {
     for(i=1;i<=5;i++)
     {
        for(j=0;j<=i;j++)
        {
         cout<<k;
         k++;
        }
     }
  }
};

class Pattern1:Pattern
{
public:
  int a;
  inline void output()
  {
     a = 5;
     for(i=1;i<=5;i++)
     {
        setw(a+1-i);
        for(j=1;j<=i;j++)
        {
         cout<<j;
        }
        for(k=i-1;k>=1;k--)
        {
         cout<<k;
        }
        cout<<endl;
     }
  }
};
int main()
{
  Pattern o;
  o.output();
  Pattern1 obj;
  obj.output();
  return 0;
}
can you tell me what is the problem in this program?
and tell me what will be the procedure to work in for loop with inline function?

Answer
hi Kedar

Inline functions gets expanded like a macro in order to increase the performance and efficiency of code ... generally small function without loops are kept inline ... and one more thing things that as it gets expanded during pre processing you can't keep loops in inline function.

regards
Joydeep Bhattacharya
http://www.scodz.com

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

TSR, Socket and Very Complex Mathematical Problem

Experience

Worked on many OOP projects with design patterns

Organizations
http://www.scodz.com

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Awards and Honors
Being a proud owner of a website of programming called http://www.scodz.com

Past/Present Clients
http://www.funforu.com http://www.dhoondho.com http://analysingc.50webs.com

©2016 About.com. All rights reserved.