fatal error C1075

 fatal error C1075

 

       这个错误括号没有配备好的错误,比如应该有两个花括号,由于不小心少了一个括号。

今天我就碰到这样一个错误,示例如下:

/*头文件CBOX.h*/

 

#ifndef CBOX_H
#define CBOX_H
#include<iostream>
using namespace std;
//#include<string>

class CBox
{
public:
    //Constructor definition  
    CBox(double lv=1.0,double wv=1.0,double hv=1.0)
        :m_Length(lv),m_Width(wv),m_Height(hv)
    {  //cout<<endl<<" Constructor called.";  
    }

/*上面两行,如果变成{//cout<<endl<<" Constructor called.";   },则会有语法错误,即“fatal error C1075”的提示,这是因为//将右边的}注释掉了,这样,语句就只有一个花括号,即一个{,当然会有错了。*/
    //Function to calculate the volume of a Box
    double Volume()const
    { return m_Length*m_Width*m_Height; }

    //Overload 'greater than' that
    //compares volumes of CBox objects.
    bool operator>(const CBox & aBox)const
{
    return this->Volume() > aBox.Volume();//第二个Volume后的()勿少了
}//否则会出现连接错误或其它语法错误
   
    bool operator>(const double & value)const
    {
        return this->Volume()>value;
    }
    //Destructor definition
   // ~CBox()
    //{//cout<<" Destructor called. "<<endl;}
private:
    double m_Length;
    double m_Width;
    double m_Height;
};

#endif

 

/*头文件CSamples.h*/

#ifndef CSAMPLES_H
#define CSAMPLES_H
#include<iostream>
using namespace std;
#include<cstring>
#include"CBOX.h"

template <class T>
class CSamples
{
public:
    CSamples(const T values[],int count)
    {//Constructor definition to accept an array of samples
        m_Free = count<100?count:100;//Don't exceed the array
        for(int i= 0;i<m_Free;i++)
            m_Values[i]=values[i];
    }
    //Constructor to accept a single sample
    CSamples(const T & value)
    {
        m_Values[0]=value;
        m_Free=1;
    }
    CSamples(){m_Free=0;}//   Nohing stored,so first is free

    //Function to add a sample
    bool Add(const T & value)
    {
        bool OK = m_Free<100;//Indicates there is a free place
        if(OK)//  OK true,so store the values
            m_Values(m_Free++)=Value;
        return OK;
    }
    //Function to botain maximum sample
    T Max()const
    {
        //Set first sample or 0 as maximum
        T theMax=m_Free?m_Values[0]:0;

        for(int i=1;i<m_Free;i++)//Check all the samples
            if(m_Values[i]>theMax )
                theMax=m_Values[i];//Store any larger sample
        return theMax;
    }
private:
    T m_Values[100];
    int m_Free;
};

#endif

 

/***********源文件*******************/

#include "CBOX.h"
#include "CSamples.h"

int main( )
{
    CBox boxes[]={
         CBox(8.0,5.0,2.0),
         CBox(5.0,4.0,6.0),
         CBox(4.0,3.0,3.0)
        };

    //Create the CSamples object to hold CBox objects
    CSamples<CBox>myBoxes(boxes,sizeof boxes/sizeof CBox);

    CBox maxBox=myBoxes.Max(); //Get the biggest box

    cout <<endl //and output its volume
        <<" The biggest box has a volume of "
        <<maxBox.Volume()
        <<endl<<endl;
    return 1;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值