| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 944 人关注过本帖
标题:大家看看哪出错了,很简单的!
只看楼主 加入收藏
cuixing158
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-9-8
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:10 
大家看看哪出错了,很简单的!
#include <iostream>
#include<string>
using namespace std;
class Student
{
private:
    int number;
    char name[20];
    char sex;
    int age;
public:
    void set(int a,char *b,char c,int d);
    void show();
};
void Student::set(int a,char *b,char c,int d)
    {
        number=a;
        strcpy(name,b);
        sex=c;
        age=d;
    }

    void Student::show()
    {
        cout<<number<<'\t'<<name<<'\t'<<sex<<'\t'<<age<<endl;

    }
怎么就错了呢,程序都是教材上面的
搜索更多相关主题的帖子: private include public number 
2014-09-08 16:32
richardw
Rank: 2
等 级:论坛游民
威 望:1
帖 子:12
专家分:14
注 册:2014-9-7
收藏
得分:5 
哪里报错了?发一下

我弄了个,没报错

程序代码:
int main(int argc, char* argv[])
{
    Student *z3 = new Student;
    z3->set(1,"Zhang",'f',16);
    z3->show();
    delete z3;
    getchar();
    return 0;
}
2014-09-08 22:16
cuixing158
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-9-8
收藏
得分:0 
回复 2 楼 richardw
咦?我的咋链接出错,用你的主函数也这种错误
我的主函数是
int main()
{
    Student stu1,stu2;
    Student *p;
    p=&stu1;
    stu1.set(101,"zhao",'m',22);
    stu2.set(102,"qian",'f',21);
    stu1.show();
    stu2.show();

    return 0;
}
错误提示:
--------------------Configuration: example2 - Win32 Debug--------------------
Compiling...
example2.cpp
D:\my_c_documents\example\example2.cpp(31) : error C2511: 'calc_pt' : overloaded member function 'void (void)' not found in 'line'
        D:\my_c_documents\example\example2.cpp(9) : see declaration of 'line'
example3.cpp
D:\my_c_documents\example\example3.cpp(3) : error C2065: 'Student' : undeclared identifier
D:\my_c_documents\example\example3.cpp(3) : error C2065: 'z3' : undeclared identifier
D:\my_c_documents\example\example3.cpp(3) : error C2061: syntax error : identifier 'Student'
D:\my_c_documents\example\example3.cpp(4) : error C2227: left of '->set' must point to class/struct/union
D:\my_c_documents\example\example3.cpp(5) : error C2227: left of '->show' must point to class/struct/union
D:\my_c_documents\example\example3.cpp(6) : error C2541: delete : cannot delete objects that are not pointers
D:\my_c_documents\example\example3.cpp(7) : error C2065: 'getchar' : undeclared identifier
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : error C2143: syntax error : missing ';' before '}'
D:\my_c_documents\example\example3.cpp(9) : fatal error C1003: error count exceeds 100; stopping compilation
执行 cl.exe 时出错.

example2.exe - 1 error(s), 0 warning(s)

新手啊,不懂啊,

[ 本帖最后由 cuixing158 于 2014-9-9 11:15 编辑 ]
2014-09-09 11:13
richardw
Rank: 2
等 级:论坛游民
威 望:1
帖 子:12
专家分:14
注 册:2014-9-7
收藏
得分:2 
D:\my_c_documents\example\example3.cpp(4) : error C2227: left of '->set' must point to class/struct/union

系统都提示你使用了"->set",而你给出的代码里根本没有,所以你都没贴对代码,这让人怎么帮你呀 -_-

你最好把你的整个工程文件打个包传上来
2014-09-09 15:35
stop1204
Rank: 9Rank: 9Rank: 9
来 自:福建省
等 级:贵宾
威 望:22
帖 子:295
专家分:1151
注 册:2013-9-8
收藏
得分:3 
一看就出来了.. 你的那个头文件的空格呢??

#include <iostream>
#include<string>  //????这里

hl928452957@gmail点com

2014-09-10 07:43
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:2 
我用vs 并没有报错

DO IT YOURSELF !
2014-09-10 08:18
七夜之华
Rank: 3Rank: 3
来 自:China
等 级:论坛游侠
威 望:5
帖 子:82
专家分:103
注 册:2014-9-7
收藏
得分:3 
朋友,我编译了下,也是没有错误,以下是我的程序,还请借鉴。
#include <iostream>
#include<string>
using namespace std;
class Student
{
private:
    int number;
    char name[20];
    char sex;
    int age;
public:
    void set(int a,char *b,char c,int d);
    void show();
};
void Student::set(int a,char *b,char c,int d)
    {
        number=a;
        strcpy(name,b);
        sex=c;
        age=d;
    }

    void Student::show()
    {
        cout<<number<<'\t'<<name<<'\t'<<sex<<'\t'<<age<<endl;

    }

int main()
{
    Student student;
    student.set(131164469,"七夜",'m',21);
    student.show();
    system("pause");
    return 0;
}
   

#############################################
##########################################
因为不懂、才要学习、只有学习、才有进步。
2014-09-10 08:46
天使梦魔
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:37
帖 子:564
专家分:2754
注 册:2007-8-29
收藏
得分:5 
编译的时候看看有没有其它cpp加在里面,提示错误cpp叫example3.cpp
2014-09-10 08:54
l3456
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:80
专家分:133
注 册:2014-4-16
收藏
得分:0 
都没有main函数

走向光明的菜鸟学生,励志成为新一代程序猿
2014-09-10 16:05
fl8962
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:14
帖 子:539
专家分:2471
注 册:2012-10-17
收藏
得分:0 
应该是你的工程里包含了其他cpp.

想抽苏烟了。
2014-09-11 12:05
快速回复:大家看看哪出错了,很简单的!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023702 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved