1. Guess the outcome generated by the following code and run it to verify your outcome!!
#include <iostream>
using namespace std;
class A {
public:
void foo() {
cout << "foo() is called in class A" << endl;
}
void foo(int i) {
cout << "foo(int i) is called in class A" << endl;
cout << "i's value: " << i << endl;
}
};
class aa : public A {
};
int main()
{
aa myaa;
myaa.foo();
myaa.foo(100);
}
2. What's wrong with the following code
#include <iostream>
using namespace std;
class A {
public:
void foo() {
cout << "foo() is called in class A" << endl;
}
void foo(int i) {
cout << "foo(int i) is called in class A" << endl;
cout << "i's value: " << i << endl;
}
};
class aa : public A {
public:
void foo() {
cout << "foo() is called in class aa" << endl;
}
};
int main()
{
aa myaa;
myaa.foo();
myaa.foo(100);
}
댓글 없음:
댓글 쓰기