header files


i m new to C++ programming and using turbo c++ as an IDE.
I m confused about some topics.
. I m trying to define a class and its attributes in a header file and defining its functions
in a .cpp extension file
.do we have to compile our own header files?
. I have also saved both the files in the same directory.
. in compiling a header file i m getting error ( syntax error in class declaration).
.my .cpp file gives no error in compilation but does not runs. i m getting
messages such as "linking noname.exe"
please help me out with this as i m not able to apply concepts in datastructures
Obligatory link: http://cplusplus.com/forum/articles/10627/

do we have to compile our own header files?


No. You #include them so they get compiled into whatever source file includes them. You do not compile them seperately.

in compiling a header file i m getting error ( syntax error in class declaration).


Then you probably have a syntax error in your class declaration. Without seeing the code it will be impossible for us to point the error out.

Show us your code. If the program is small, go ahead and post all of it so we can try compiling it ourselves. If it's too big for that, try to reproduce the same problems you're getting in a smaller program.
code for CAT.h

class CAT
{
public :
int age;
int roll;
void mew();
};





code for CAT.cpp
#include"CAT.h"
#include<iostream.h>
void CAT:: mew()
{
cout<<"mew";
}

void main()
{
CAT frisky;
frisky.mew();

}




Well there are a few errors, but nothing that would cause the problems you're describing. Here's the changes I made to cat.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "header.h"
#include <iostream>  // <iostream>, not <iostream.h>

void CAT:: mew()
{
    std::cout<<"mew";  // std::cout, not cout (or you could put 'using namespace std' somewhere)
}

int main()  // int main, not void main
{
    CAT frisky;
    frisky.mew();
}


With those changes it compiles and runs fine on my machine.

What errors are you getting specifically? Like can you paste the exact errors?
I am not getting errors in my previous code.
however after compiling without any errors
when I try to run the program I am
getting message -"linking CAT.EXE" and no output.
I am using turbo c++ as an IDE
Are you sure you're running the program?

Try just running the exe directly? like find CAT.EXE and run it from outside Turbo C++
no its not running , a black screen is blinking for a second
Its most probably a problem with the include or library path specification.
Check it somewhere in options...
Topic archived. No new replies allowed.