inline function????

15 views
Skip to first unread message

Hammad muddassir

unread,
May 11, 2013, 10:37:34 AM5/11/13
to cs1003-s...@googlegroups.com
                                                                        ASSLAM-O-ALLIKIUM!

Respected Sir :

                       what does inline keyword do in classes?????
                                   &
                          How can we create a program that makes text file but name is chossen by user.for exAMPLE IF user whishes he want to create file of hammad.txt so program should make file of that name?????????

Sami Ullah Kashif

unread,
May 11, 2013, 12:14:03 PM5/11/13
to cs1003-s...@googlegroups.com
If you put the keyword "inline" before a function, then it is not treated as a function by the compiler. Instead it is treated as normal lines of code. Advantage is that you are saved from the overhead of calling functions on the stack.

If you want to take the name of the file input from the user, its pretty simple. You can write the following code:

string filename;
cout << "Please enter file name: " << endl;
cin >> filename;

ofstream outFile(filename, ios::out);

Regards,
Sami

Hammad muddassir

unread,
May 11, 2013, 12:26:06 PM5/11/13
to cs1003-s...@googlegroups.com
for example
in class
inline void abc();
in cpp
void class::abc()
{

Hammad muddassir

unread,
May 11, 2013, 12:26:45 PM5/11/13
to cs1003-s...@googlegroups.com
what will happen here?????

Sami Ullah Kashif

unread,
May 11, 2013, 12:42:08 PM5/11/13
to cs1003-s...@googlegroups.com
The function in the class abc has become inline now. You don't need to understand what happens under the hood here.

Regards,
Sami
Reply all
Reply to author
Forward
0 new messages