forward_list Question 9

Last Updated :
Discuss
Comments

Predict the output of the following code:

C++
#include <bits/stdc++.h>
using namespace std;
class A
{
  public:
    int x, y;
    A(int a, int b) : x(a), y(b)
    {
    }
};

int main()
{
    forward_list<A> fl = {{1, 2}};
    fl.insert_after(fl.begin(), {3, 4});
    auto it = ++fl.begin();
    cout << it->x << " " << it->y;
    return 0;
}


Compiler Error

3 4

1 2

0 0

Share your thoughts in the comments