tags:

views:

286

answers:

4

Possible Duplicate:
main.cpp access member function of another .cpp witin same source file

i use two cpp files within same sourcefile another.cpp here i use one class and member function like ,

Another.cpp
    class A
    {
    public :
    int Add();
    };
    int A::Add()
    {
    -----
    -------
    }
    ------------------
    main.cpp
    here also,
    class B
    {
    --------
    }
    int main()
    {
    here ,can i possible to create an object for class A and access Add function without(using without header file is important)...
    return 0;
    }

thanks in advance..

A: 

Your best bet is to create an .h file and move the class A declaration there.

If you really don't want to use an .h file - just include the Another.cpp file but then you will have to take care to not include it into any other file and also exclude Another.cpp from direct compilation.

sharptooth
A: 

I don't think I'm fully understanding your scenario, but the compiler needs to know the definition of Class A to call it from main.cpp.

What's the reason you can't use a header file?

Wade Williams
A: 

If you want to use class A in main.cpp you're going to need to put something in a file that gets #included, whether it's the class definition, or a set of C-style function definitions that operate on the class and return a "token" that let you access it. Why can't you use a header file?

Colen
A: 

I'm not sure why you don't want to use a header file, so you might want to re-check your reasoning behind that.

However if you have the class definition in both .cpp files, you will be able to use objects created in one file with the other.

Of course another method is to #include the other .cpp file and exclude it from the linker. But if you're going to go to this length why not use a header file really ?

Bad Sector
i am trainee in an organization ...but i need some useful research through you and all....here i want to ask one question,your point of view ,any idea to create an class object in a .cpp file into another.cpp file without header or dll
Rajakumar