#include <iostream>
#include "string"
using namespace std;
class Screen;
class Cursor
{
typedef string::size_type index;
void relocate(index, index, Screen& C)
{cout << C.name << endl;}
private:
};
class Screen
{
friend void Cursor::relocate(Cursor::index, Cursor::index, Cursor::Screen& C);
Screen(string &b):name(b){}
private:
string name;
};
int main()
{
Cursor A;
Screen B("HAHA");
A.relocate(1,1,B);
system("PAUSE");
return 0;
}
error C2027: use of undefined type 'Screen'
error C2228: left of '.name' must have class/struct/union type
error C2039: 'Screen' : is not a member of 'Cursor'
error C2664: '__thiscall Screen::Screen(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)' : cannot convert parameter 1 from 'char [5]'
to 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &'
error C2248: 'relocate' : cannot access private member declared in class 'Cursor'
可能是涉及哪个类先定义,哪个先声明的问题,~~迷惘,求解释
求改正
#include "string"
using namespace std;
class Screen;
class Cursor
{
typedef string::size_type index;
void relocate(index, index, Screen& C)
{cout << C.name << endl;}
private:
};
class Screen
{
friend void Cursor::relocate(Cursor::index, Cursor::index, Cursor::Screen& C);
Screen(string &b):name(b){}
private:
string name;
};
int main()
{
Cursor A;
Screen B("HAHA");
A.relocate(1,1,B);
system("PAUSE");
return 0;
}
error C2027: use of undefined type 'Screen'
error C2228: left of '.name' must have class/struct/union type
error C2039: 'Screen' : is not a member of 'Cursor'
error C2664: '__thiscall Screen::Screen(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)' : cannot convert parameter 1 from 'char [5]'
to 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &'
error C2248: 'relocate' : cannot access private member declared in class 'Cursor'
可能是涉及哪个类先定义,哪个先声明的问题,~~迷惘,求解释

