Home Forums C Programming inline function

Viewing 2 reply threads
  • Author
    Posts
    • #2018
      vishal
      Participant

      :o Actually i want to know about inline functions. the basic restrictions on them and where to use it. whether we can use return statement on it or not and the explanation about it.

      I am following balagurusamy fo it and on page no. 84 of it they hav used return in inline. Also i want to know about the restrictions that why we can not use loops,switch or while in inline. And if possible pls give me some nice tutorial of friend functions

    • #3258
      theblinger
      Participant

      HI,
      You can get good c++ tutorial in cplusplus.com website.

      Raghuram

    • #3259
      S.Thananchayan
      Participant
      #include 
      using namespace std;
      void Menu();
      int GetSomething();
      inline void do_something (char* a)
      {
       cout << a  << endl;
      }
      inline void do_something_else (char* b)
      {
       cout << b << endl;
      }
      inline void and_even_more (char* c)
      {
       cout << c << endl;
      }
      int main()
      {
       int loop;
       int z;
       for (loop = 0; loop < 10; loop++)
        do_something("Dont taze me bro");
       cout << "Press 1 or 2 for answer";
       cin >>z;
       if (z==1)
        do_something_else("now you do what they told ya");
       if (z==2)
        and_even_more("Everyone fear the machine");
       else
        
          Menu();
        
          int fun;
          fun = GetSomething();
        
          switch (fun)  {
              case 1:
                  std::cout << "Wee" << std::endl;
                  break;
              case 2:
                  std::cout << "Dude" << std::endl;
                  break;
              case 3:
                  std::cout << "Quitting" << std::endl;
                  break;
              default:
                  std::cout << "aInvalid selection" << std::endl;
                  break;
          }
          return 0;
      }
      void Menu()
      {
          std::cout << "--- Menu ---" << endl;
          std::cout << "1=Wee" << endl;
          std::cout << "2=Dude" << endl;
          std::cout << "3=Quit" << endl;
      }
      int GetSomething()
      {
          int selection;
          std::cout << "Enter Selection: ";
          std::cin >> selection;
          return selection;
      }
Viewing 2 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.