Skip to main content
deleted 20 characters in body
Source Link
java_doctor_101
  • 3.4k
  • 6
  • 50
  • 84

There is nothing wrong with this implementationMay be it's your compiler, here is the full running codeMine gives no error or warnings.

#include <iostream> 
#include <vector>
using namespace std;



struct foo {
int x;
vector < foo > bar;
};


int main()
{
foo a;
foo b;
b.x = 3;
a.bar.push_back(b);
cout<<a.bar[0].x;
    cout<<"\n";
return 0;
} 

enter image description here

There is nothing wrong with this implementation, here is the full running code.

#include <iostream> 
#include <vector>
using namespace std;



struct foo {
int x;
vector < foo > bar;
};


int main()
{
foo a;
foo b;
b.x = 3;
a.bar.push_back(b);
cout<<a.bar[0].x;
    cout<<"\n";
return 0;
} 

enter image description here

May be it's your compiler, Mine gives no error or warnings.

#include <iostream> 
#include <vector>
using namespace std;



struct foo {
int x;
vector < foo > bar;
};


int main()
{
foo a;
foo b;
b.x = 3;
a.bar.push_back(b);
cout<<a.bar[0].x;
    cout<<"\n";
return 0;
} 

enter image description here

Source Link
java_doctor_101
  • 3.4k
  • 6
  • 50
  • 84

There is nothing wrong with this implementation, here is the full running code.

#include <iostream> 
#include <vector>
using namespace std;



struct foo {
int x;
vector < foo > bar;
};


int main()
{
foo a;
foo b;
b.x = 3;
a.bar.push_back(b);
cout<<a.bar[0].x;
    cout<<"\n";
return 0;
} 

enter image description here