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;
}