What will be the output of the following C++ code? [code] #include <iostream> using namespace std; class Testpm {

What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    class Testpm 
    {
        public:
        void m_func1() 
        { 
            cout << "func1\n";
        }
        int m_num;
    };
    void (Testpm :: *pmfn)() = &#038;Testpm :: m_func1;
    int Testpm :: *pmd = &#038;Testpm :: m_num;
    int main() 
    {
        Testpm ATestpm;
        Testpm *pTestpm = new Testpm;
        (ATestpm.*pmfn)();
        (pTestpm ->* pmfn)();
        ATestpm.*pmd = 1;
        pTestpm ->* pmd = 2;
        cout << ATestpm.*pmd << endl
        << pTestpm ->* pmd << endl;
    }
A. func1
B.
func1
func1
C.
1
2
D.
func1
func1
1
2
 
Answer: d
Explanation: In this program, As we are passing the value twice to the method
in the class, It is printing the func1 twice and then it is printing the given
value.
Output:
Code:
$ g++ ptm1.cpp
$ a.out
func1
func1
1
2
 

Tìm kiếm

Back
Top