回 帖 发 新 帖 刷新版面

主题:[讨论]请各位朋友帮忙调试一下,谢谢!

#include <iostream.h>
 class szcl {
      int e;        
 public:
      szcl ( ) { e = 0; }    
      szcl ( int value ) { e = value; }    
      int get_value ( ) { return e; }     
 }
main ( ) {
   szcl a1[3] = { 3, 5, 7 }, *elem;   
   for ( int i=0, i<3, i++ ) 
       cout << a1[i].get_value ( ) << “\n”;        //打印静态数组
   elem = &a1;    
   for ( int i=0, i<3, i++ ) {
       cout << elem→get_value( ) << “\n”;        //打印动态数组
       elem++;
    } 
    return 0;
}            

回复列表 (共4个回复)

沙发

以下是我调试的.
#include <iostream>
using namespace std;
 class szcl {
      int e;        
 public:
      szcl ( ) { e = 0; }    
      szcl ( int value ) { e = value; }    
      int get_value ( ) { return e; }     
 };
int main ( )
{
   szcl a1[3] = { 3, 5, 7 },*elem;   
   for ( int i=0; i<3;i++ ) 
       cout << a1[i].get_value ( ) << "\n";        //打印静态数组
   elem=a1;    
   for ( int i=0; i<3; i++ ) {
       cout << (*elem).get_value( ) << "\n";        //打印动态数组
       elem++;
    } 
    system("pause");
    return 0;
}                        

板凳

这里的类没有private和public,那个e是默认为private吧?

3 楼

struct 默认为public
class 默认为private

4 楼

两个类的顺序问题

我来回复

您尚未登录,请登录后再回复。点此登录或注册