1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What's wrong in my c coding (constructors)?

  1. Jul 6, 2006 #1
    #include<stdio.h>
    #include<conio.h>
    class info
    {
    int name,roll;
    public:
    void input();
    void output();
    }
    void info::input()
    {
    printf("Enter your name and rollno \n");
    scanf("%c%d" ,&name,&roll);
    }
    void info::eek:utput()
    {
    printf("Your name is %c \n" ,name);
    printf("Your rollno is &d \n" , roll);
    }
    class marks :public info
    {
    int math,bio,eng;
    public:
    void input();
    void output();
    }
    void marks::input()
    {
    info::input() ;
    printf("Input marks : \n");
    scanf("%d%d%d" , &math , &bio , &eng);
    }
    void marks::eek:utput()
    {
    info::eek:uput();
    printf("Your marks are %d %d %d \n" ,math,bio,eng);
    }
    void main()
    {
    clrscr();
    class marks m;
    m.input();
    m.output();
    getch();
    }

    ---------------

    I have darkened the line in which my compiler shows the error...i dont seem to find any ... :bugeye: , it says "Declaration Syntax Error")
     
  2. jcsd
  3. Jul 6, 2006 #2
    Are you using a C++ compiler or a C compiler?
     
  4. Jul 6, 2006 #3

    DaveC426913

    User Avatar
    Gold Member

    Is 'info' a reserved word? Try changing it.
     
  5. Jul 6, 2006 #4
    Put a semicolon after the class declarations:
    Code (Text):
    class info
    {
    int name,roll;
    public:
    void input();
    void output();
    };
     
    etc.

    You need a C++ compiler for this.
     
  6. Jul 6, 2006 #5
    heh, my program would look like this:

    Code (Text):

    using namespace std;
    while(Subject.GetNext())
    {
       cout >> "You'r Grade for ">> Subject.Get() >> " is ";
       cout >> "F!" >> endl;
    }
     
     
    Last edited: Jul 6, 2006
  7. Jul 6, 2006 #6
    Too bad it won't compile.
     
  8. Jul 7, 2006 #7
    do constructors worl only in C++ and not C???
     
  9. Jul 7, 2006 #8
    C does not have classes. A C compiler will not recognize the class keyword.

    C does have structures. In C++, a structure can have a constructor as well as member functions. I do not know whether structs in C can have constructors or other member functions.

    Good luck,
    Tim
     
  10. Jul 7, 2006 #9
    C structs(different from C++ structs) cannot have functions...they can have function pointers but not functions.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: What's wrong in my c coding (constructors)?
  1. Critique my C++ code (Replies: 11)

Loading...