Exam4Training

A(string s) { this?

What happens when you attempt to compile and run the following code?

#include <iostream>

#include <string>

using namespace std;

class A {

public:

string s;

A(string s) { this?>s = s; }

};

class B {

public:

string s;

B (A a) { this?>s = a.s; }

void print() { cout<<s; }

};

int main()

{

A a("Hello world");

B b=a;

b.print();

}
A . It prints: Hello world
B.It prints: Hello
C.Compilation error
D.None of these

Answer: A

Exit mobile version