Stupid C++ compiler: why cannot see things defined later on???

Hi C++ designers,

I want to make a suggestion to C++ compiler designers to adopt one feature from Java, that is the ability to see class members defined later on. For example,
class A{
public:
 void a(){
  B b;
  b.func();
 }
 void func(){}
};

class B{
public:
 void func(){
  A a;
  a.func();
 }
};

Java can handle this with no problem, but for C++, you have to declare a() first and define it later on outside the class {}, which is very disgusting, unreadable and inconvenient.
void A::a(){
 B b;
 b.func();
}

Because of this, C++ programmers need to create additional files and headers to accommodate this. And you can only include the header but not the cpp file. Otherwise, compiler will complain on the redefinition, which is stupid, very inconvenient. Well, if a function is defined twice, if they are the same, what problem will there be??? If they are different, why not post a warning and adopt the latest version first. That's why Java is better in this aspect.

I know that C++ standards have been revised many times over the years. The newest C++11 standard supports "auto" variable definition adopting one of my previous ideas. They also imported many useful Boost library functions like boost::thread, boost::shared_ptr, etc. It's quite surprising to me that those famous designers have not learned anything useful from Java, such as this simple but efficient compiler-level feature.
I hope this can be a new feature for C++12 standard. Thanks!

Wang Xuancong

Comments

Sign In or Register to comment.