在DVC C++5.11中编写好类的头文件,函数实现文件,程序运行文件然后总之通不过编译,求解
//头文件:
#include
#ifndef STRNGBAD_H_
#define STRNGBAD_H_
class StringBad
{
private:
char * str;
int len;
static int num_strings;
public:
StringBad(const char * s);
StringBad();
~StringBad();
friend std::ostream & operator <<(std::ostream & os,const StringBad & st);
};
#endif
//函数实现文件
#include "StringBad.h"
using std::cout;
int StringBad::num_strings=0;
StringBad::StringBad(const * s)
{
len=std::strlen(s);
str=new char[len+1];
std::strcpy(str,s);
num_strings ++;
cout<": \""<"\" object create\n";
}
StringBad::StringBad()
{
len=4;
str=new char[4];
std::strcpy(str,"c++");
num_strings++;
cout<": \""<"\"default object create\n";
}
StringBad::~StringBad()
{
cout<<"\""<"\"object deleted, ";
--num_strings;
cout<" left\n";
delete []str;
}
StringBad::operator <<(std::ostream & os,const StringBad & st)
{
os<return os;
}
//

运行文件:
#include
using std::cout;
#include "StringBad.h"
void callme1(StringBad &);
void callme2(StringBad);
int main()
{
using std::endl;
{
cout<<"StringBad an inner block.\n";
StringBad headline1 ("Celery Stalks at Midnight");
StringBad headline2 ("Lettuce Prey");
StringBad sports("Spinach Leave Bow1 for Dollars");
cout<<"headline1: "<"headline2: "<"sports: "<callme1(headline1);
cout<<"headline1: "<callme2(headline2);
cout<<"headline2: "<"Initialize one object to another:\n";
StringBad sailor=sports;
cout<<"sailor: "<"Assign one object to another:\n";
StringBad knot;
knot=headline1;
cout<<"knot: "<"Exiting the bloak.\n";
}
cout<<"End of main()\n";
return 0;
}
void callme1(StringBad & rsd)
{
cout<<"String passed by reference:\n";
cout<<"\""<"\"n";
}
void callme2(StringBad sb)
{
cout<<"String passed by value:\n";
cout<<"\""<"\"n";
}
“Devil组”引证GPT后的撰写:
有以下几个问题: