| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 764 人关注过本帖
标题:const指针,通不过编译,求助
只看楼主 加入收藏
NordicNavy
Rank: 1
来 自:地球
等 级:新手上路
帖 子:30
专家分:0
注 册:2008-10-20
收藏
 问题点数:0 回复次数:1 
const指针,通不过编译,求助
#include <iostream>
using namespace std;

class Rectangle
{
       public:
               Rectangle();
               ~Rectangle();
               //void SetLength(int length){itsLength = length;}
               //int GetLength() const { return itsLength;}
               void SetWidth(int width){ itsWidth = width;}
               int GetWidth() const { return itsWidth;}
                             
      private:
                //int itsLength;
                int itsWidth;
}
Rectangle::Rectangle()
{
      itsWidth = 5;
                       }
              //itsLength = 6;
              

Rectangle::~Rectangle()
{}
int main()
{
     Rectangle * pRect = new Rectangle;
     const Rectangle * pConstRect = new Rectangle;
     Rectangle * const pConstPtr = new Rectangle;
     
     cout << "pRect width: " << pRect->GetWidth() << "feet\n";
     cout << "pConstRect width: " << pConstRect->GetWidth() << " feet\n";
     cout << "pConstPtr width. " << pConstPtr->GetWidth() << " feet\n";
     pRect -> SetWidth(10);
     pConstRect -> SetWidth(9);
     pConstPtr -> SetWidth(10);
     
     cout << "pRect width: " << pRect->GetWidth() << "feet\n";
     cout << "pConstRect width: " << pConstRect->GetWidth() << " feet\n";
     cout << "pConstPtr width. " << pConstPtr->GetWidth() << " feet\n";
     system("pause");
     }
搜索更多相关主题的帖子: const 指针 编译 
2008-11-04 00:23
nwpu063417
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:428
专家分:28
注 册:2007-5-11
收藏
得分:0 
楼主貌似以前学过Java。
类的声明后边要有;
使用构造函数要加括号:
Rectangle * pRect = new Rectangle();
主要就这两个问题吧

2008-11-04 23:31
快速回复:const指针,通不过编译,求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032225 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved