当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 在vb & sql server的程序中,为了使数字输出标准化,需要用format()函数, 例如: rs.open "select ch,format(sl,#0.0000) ,formatjh,#,##0.00) from thd ", cn, adopenstatic, adlockpessimistic set datagrid1.datasource ......
 ·这个错误提示是什么怎么改    »显示摘要«
    摘要: 我的程序中: void __fastcall tform1::formclose(tobject *sender, tcloseaction &action) { delete tbitmap; } 和 void __fastcall tform1::formcreate(tobject *sender) { doublebuffered=true; image1->ali......


如何在一个类中去控制另外一个类的变量

如何在一个类中去控制另外一个类的变量?  
  在MFC中是不是不很支持c++语法?  
  在一个类中是不是不能控制,修改另一个类的静态变量?  
  如:  
      class   a  
  {  
  public:  
  static   int   s;  
  };  
   
  class   b  
  {  
  public:  
  void   f();  
  };  
  int   a::s   =   0;  
  void   b::f()  
  {  
  a::s   =   2;  
  }  
  在c++中可以但是在MFC中好象不行。请高手指教。

NO.1   作者: Pipi0714

在另一个类中声明该类然后调用该类的静态变量

NO.2   作者: soso82

MFC本来就主要用C++编写的,肯定完全支持C++。你这种VC里也支持的,可能你的一个类变量在另一个文件定义,你要使用,就用到extern

NO.3   作者: freeshoot

是不是类定义在不同文件中?  
  试试下面的代码:  
   
  //   File   A.h  
   
  class   a  
  {  
  public:  
      static   int   s;  
  };  
   
  //   File   A.cpp  
   
  #include   A.h  
  int   a::s   =   0;  
   
  //   File   B.h  
   
  class   b  
  {  
  public:  
      void   f();  
  };  
   
  //   File   B.cpp  
   
  #include   A.h  
  #include   B.h  
   
  class   a;  
  void   b::f()  
  {  
        a::s   =   2;  
  }  
 

NO.4   作者: dupenf

友元类

NO.5   作者: ioiogo

友元类可以的!!!!

NO.6   作者: pHyq

#include   <stdio.h>  
  class   a  
  {  
  public:  
  static   int   s;  
  };  
   
  class   b  
  {  
  public:  
  void   f();  
  };  
   
  int   a::s   =   0;  
   
  void   b::f()  
  {  
  a::s   =   2;  
  }  
   
  int   main()  
  {  
  b   *pb=new   b;  
  printf("%d\n",a::s);  
  pb->f();  
  printf("%d\n",a::s);  
  return   0;  
  }  
  也许我没理解你的意思,不过MFC是完全支持C++的  
 

NO.7   作者: martingod

是不是应该先在B类的头文件中先声明A,再创建对象.或者你试下将变量类型改成extern.

NO.8   作者: nomenn

直接创建对象引用就可以了


    摘要: 假如通过一个索引网页datagrid中一个超链接转到另一个网页查看详细信息。 这样的要求就导致了当查看详细信息的时候,必须通过数据库查询返回一条记录。 asp.net中,返回一条记录(使用dataset或datareader随便),怎样把记录中的数据邦定到网页上? 在数据字段不多的时候,勉强可以使用lebel,然后手工绑定,但是如果数据字段很多,有20个,30个怎么办? 我不想使用data......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE