f0909的3个问题

源码:

//student.h

#include<iostream>
using namespace std;

class Student;
class Student
{
const int id;

public:
Student(int d): id(d) { cout<<"student\n"; )
void print() { cout<<id<<"\n"; }

};

class Tutor
{
Student s;

public:
Tutor(Student & st):s(st)
{
   cout<<"Tutor\n";
   s.print();
}

};

//f0909.cpp

#include"student.h"

extern Student ra;

Tutor je(ra);
int main()
{
return 0;
}

//f0909_2.cpp

#include"student.h"
extern Student ra(18);

编译错误:

f:\题目\student.h(19) : error C2079: 's' uses undefined class 'Student'
f:\题目\f0909.cpp(1) : error C2059: syntax error : 'PCH creation point'
f:\题目\f0909.cpp(3) : error C2238: unexpected token(s) preceding ';'
f:\题目\f0909.cpp(5) : error C2059: syntax error : 'PCH creation point'
f:\题目\f0909.cpp(5) : error C2238: unexpected token(s) preceding ';'
f:\题目\f0909.cpp(6) : error C2059: syntax error : 'PCH creation point'
f:\题目\f0909.cpp(7) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
f:\题目\f0909.cpp(10) : fatal error C1004: unexpected end of file found

解决:绿色代码改为红色

Student(int d): id(d) { cout<<"student\n"; }

原因:缺少右 },或写成)

链接错误: LNK2001: unresolved external symbol class Student ra (?ra@@3VStudent@@A)

解决:运行f0909_2.cpp,再运行f0909.cpp

原因:未将f0909_2.cpp加到工程中去。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值