#include<iostream.h>using namespace std;

解决方案 »

  1.   

    出现的error是error C2660: 'MyCout' : function does not take 1 parameters
      

  2.   

    int main(int argc, char* argv[])
    {
    int j=10;
    AAA test;
    test.MyCout(j);
    return 0;
    }
      

  3.   

    BBB 并没有定义MyCount(int)型的函数
    AAA 倒可以
    AAA test;
    test.MyCount(j);
      

  4.   

    不好意思,class BBB那一行应该改为class BBB:public AAA
      

  5.   

    我的意思是把class BBB那一行改为class BBB:public AAA后还是有这个编译问题呀????
      

  6.   

    int main(int argc, char* argv[])
    {
    int j=10;
    BBB test;
    test.AAA::MyCout(j);
    return 0;
    }
      

  7.   

    或者去了BBB中的class BBB:public AAA
    {
    public:
    //void MyCout()
    //{
    //cout<<"BBB::none\n";
    //}
    };
      

  8.   

    to bskay(bskay):
      怎样理解这样的现象,算不算编译器的一个BUG
      

  9.   

    问的有深度。BBB 把名字 MyCount 覆盖了基础类(AAA)的 MyCount
    这个时候,AAA::MyCount 就无效了。这是 C++ 的规则。如果你一定要用,你可以这么做
    class BBB ......
    {
    ...void MyCount( int i )
    {
    AAA::MyCount( i );
    }...
    };根据内联原则,实际上没有带来额外的编码。
      

  10.   

    to scklotz(晓春):
       BBB 把名字 MyCount 覆盖了基础类(AAA)的 MyCount
    这个时候,AAA::MyCount 就无效了。这是 C++ 的规则。
       你在那个地方看见类似这句话的,能不能介绍给我???
      

  11.   

    #include <iostream.h>class AAA
    {
    public:
    void MyCout()
    {
    cout<<"AAA::none\n";
    }
    void MyCout(int i)
    {
    cout<<"AAA::int"<<i<<endl;
    }
    };
    class BBB
    {
    public:
    void MyCout()
    {
    cout<<"BBB::none\n";
    }
    };
    int main(int argc, char* argv[])
    {
    int j=10;
    BBB test;
    test.MyCout();
    return 0;
    }
      

  12.   

    #include <iostream.h>class AAA
    {
    public:
    void MyCout()
    {
    cout<<"AAA::none\n";
    }
    void MyCout(int i)
    {
    cout<<"AAA::int"<<i<<endl;
    }
    };
    class BBB
    {
    public:
    void MyCout()
    {
    cout<<"BBB::none\n";
    }
    };
    int main(int argc, char* argv[])
    {
    int j=10;
    BBB test;
    test.MyCout();
    return 0;
    }
      

  13.   

      每当派生类有某个member与其基类的member同名时,便会遮蔽住基类的那份member,也就是说,派生类对该名称的任何运用,都会被决议为该派生类自身的那份member,而非继承而来的那份member。这种情况下,如果要在派生类中使用继承而来的那份member ,必需利用class scope运算符加以修饰              ---Stanley B.Lippan《Essential C++》(侯译本 P152)
      

  14.   

    你的程序写得有问题,如果BBB是从AAA继承就应该这样定义BBB:class BBB:public AAA;如果BBB不是继承自AAA,则BBB的MyCout()方法就应该带一个参数,或者调用的时候不带参数。
      

  15.   

    进行如下改动后,方可编译通过.不过如果在开发中要这么做的话,最好将MyCout声明为Virtual.
    另外,我觉得这是一个正常的现象,函数的重载应该有一定的范围限制,它不应超出自身类的范围.
    还有,如果你把BBB中的MyCout去掉,则也可编译通过.
    #include "stdafx.h"
    #include<iostream.h>
    class AAA
    {
    public:
    void MyCout()
    {
    cout<<"AAA::none\n";
    }
    void MyCout(int i)
    {
    cout<<"AAA::int"<<i<<endl;
    }
    };
    class BBB:public AAA //必需从AAA继承
    {
    public:
    void MyCout()
    {
    cout<<"BBB::none\n";
    }
    void MyCout(int i)  //必需显性定义明
    {
    AAA::MyCout(i);
    }
    };
    int main(int argc, char* argv[])
    {
    int j=10;
    BBB test;
    test.MyCout(j);
    return 0;
    }
      

  16.   

    在CWND派生类中使用:
    MessageBox(NULL,"Hello","",MB_OK);
    也会出错,它并没有调用全局函数MessageBox,应改为:
    ::MessageBox(NULL,"Hello","",MB_OK);
    与你的情况一个道理。我觉得似乎有一种把函数决议为最内层次的意思。
      

  17.   

    我觉得scklotz(晓春)等说的是正确的。
    btw,你们是不是也在看《Inside the c++》?
      
    其实这样一种情况与java有点不一样,在java中
    子类只会覆盖父类中完全同名,同参数的方法,其他同名,不同参数的方法,
    一样保留,可以调用,与这里的情况有点不同。(我个人觉得c++的不好,起码是一致性不好。)
      

  18.   

    #include<iostream.h>
    不应该用了吧?
      

  19.   

    #include "stdafx.h"
    #include<iostream.h>
    class AAA
    {
    public:
    void MyCout()
    {
    cout<<"AAA::none\n";
    }
    void MyCout(int i)
    {
    cout<<"AAA::int"<<i<<endl;
    }
    };
    class BBB
    {
    public:
    void MyCout()
    {
    cout<<"BBB::none\n";
    }
    };
    int main(int argc, char* argv[])
    {
    int j=10;
    BBB test;  // 应该改成 AAA test;
    test.MyCout(j);
    return 0;
    }因为BBB类里没有宣告void MyCout(int i),而是在AAA里宣告的void MyCout(int i) 
      

  20.   

    将main()改为int main(int argc, char* argv[])
    {
    int j=10;
    BBB test; 
    AAA* ptest = &test;
    ptest->MyCout(j);
    return 0;
    }或int main(int argc, char* argv[])
    {
    int j=10;
    BBB test;
    static_cast<AAA>(test).MyCout(j);
    return 0;
    }均可编译由那位大哥能说明一下为什么???