- 论坛徽章:
- 0
|
1 #include <iostream.h>
2 #include <string.h>
3
4 class Student{
5 public:
6 Student(char* pName="no name")
7 {
8 strncpy(name,pName,sizeof(name));
9 name[sizeof(name)-1]='\0';
10 }
11
12 Student(Student& s)
13 {
14 strcpy(name,"copy of ");
15 strcat(name,s.name);
16 }
17
18 protected:
19 char name[40];
20 };
21
22 Student fn(Student stu)
23 {
24 return stu;
25 }
26
27 int main()
28 {
29 Student randy("Randy");
30
31 Student stu1 = fn(randy);
32
33 return 0;
34 }
35 |
编译出错信息如下:
test.cpp: In function `int main()':
test.cpp:31: no matching function for call to `Student::Student(Student)'
test.cpp:13: candidates are: Student::Student(Student&)
test.cpp:7: Student::Student(char* = "no name") |
刚开始学c++,还请大家多多帮忙.
[ 本帖最后由 happy_flying 于 2008-7-31 11:06 编辑 ] |
|