新手 遇到的 C++编译错误,望高手指点一二。
lesson8.h#ifndef lesson8_h
#define lesson8_h
#include <iostream>
using namespace std;
#define unlong unsigned long
#define unint unsigned int
class leftover
{
public:
unlong left (unlong num,unint ct);
char *left (const char *str,int n);
};
#endif
lesson8.cpp
#ifndef lesson8_cpp
#define lesson8_cpp
#include "lesson8.h"
unlong leftover::left (unlong num,unint ct)
{
unint digits =1;
unlong n =num;
if(ct==0 || num==0)
{
return 0;
}
while(n/=10)
{
digits++;
}
if(digits>ct)
{
ct=digits-ct;
while(ct--)
{
num /=10;
}
return num;
}
else
{
return num;
}
}
char leftover::*left (const char *str,int n)
{
if(n<0)
{
n=0;
}
char *p=new char[n+1];
int i;
for (i=0;i<n&&str[i];i++)
{
p[i]=str[i];
}
while(i<=n)
{
p[i++]='\0';
}
return p;
}
#endif
my_lesson8.cpp
#ifndef my_lesson8_cpp
#define my_lesson8_cpp
#include "lesson8.h"
leftover MoveLeft;
int main()
{
char *trip =" hawaii!! ";
unlong n = 12345678;
int i;
char *temp;
for(i=1;i<10;i++)
{
cout<<MoveLeft.left(n,i)<<endl;
temp=MoveLeft.left(trip,i);
cout<<temp<<endl;
delete []temp;
}
return 0;
}
#endif
错误信息
--------------------Configuration: lesson8 - Win32 Debug--------------------
Compiling...
lesson8.cpp
e:\c#\c++ project\lesson8\lesson8.cpp(65) : error C2440: 'return' : cannot convert from 'char *' to 'char leftover::*'
There is no context in which this conversion is possible
Error executing cl.exe.
lesson8.exe - 1 error(s), 0 warning(s)