| | |
Can an Obj-C Class Used with C++?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
there is no such thing as an "obj-c" class. C language knows nothing about classes. Maybe you mean a structure object declared in a c translation unit (*.c program) ?
if you have a large group of objects
C++ Syntax (Toggle Plain Text)
// *.cpp file extern C int myint;
if you have a large group of objects
C++ Syntax (Toggle Plain Text)
// *.cpp file extern C { int myint; // blabla };
Last edited by Ancient Dragon; Feb 22nd, 2009 at 10:28 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
The question is Objective-C language.
As far as I know, GNU Objective-C++ allows some mix of C++ and Object-C modules (I never used it).
http://en.wikipedia.org/wiki/Objective-C
See also:
http://www.faqs.org/faqs/computer-lang/Objective-C/faq/
As far as I know, GNU Objective-C++ allows some mix of C++ and Object-C modules (I never used it).
http://en.wikipedia.org/wiki/Objective-C
See also:
http://www.faqs.org/faqs/computer-lang/Objective-C/faq/
What I am guessing is that you dont have the source of of the .obj(or .o) file.
Don't worry. If you know what all prototypes where there in the source file, you can create a header file which have all the prototypes and then compile it. It will compile easily. But when you are linking, be sure to link the object file along the header file and your main source file.
I know its getting bit confusing so heres a brief example.
Lets say the object file contains a structure and a function
someobj.c
But you dont have the code have the code of the above file right? You just have the precompiled obj file( which will be a .o file or a .obj file).
Now I want you to create a new file containing the prototype(not the definition) of all the data structure and function used. In our example this will be:
myobj.h
Now just include the myobj.h in your main cpp program
main.cpp
Now compile the main.cpp. In g++ you compile with the compile only flag -c
And then you link the main.o and the myobj.o together to make your executable
And you are done;
Note that you can avoid writing the myobj.h by directly declaring the prototype in your main program.
I hope it helps
Also note that your code of the myobj.o i.e myobj.c should not contain any c++ incompatible code. Also, the object file should have been of the same platform as your program(i.e. it should not been that you compiled the .obj file on a Unix and now try to link in a windows box)
Don't worry. If you know what all prototypes where there in the source file, you can create a header file which have all the prototypes and then compile it. It will compile easily. But when you are linking, be sure to link the object file along the header file and your main source file.
I know its getting bit confusing so heres a brief example.
Lets say the object file contains a structure and a function
someobj.c
C++ Syntax (Toggle Plain Text)
struct myType { int a; float b; }; int f1(myType x) { return( x.a); }
But you dont have the code have the code of the above file right? You just have the precompiled obj file( which will be a .o file or a .obj file).
Now I want you to create a new file containing the prototype(not the definition) of all the data structure and function used. In our example this will be:
myobj.h
C++ Syntax (Toggle Plain Text)
struct myType; int f1(myType);
Now just include the myobj.h in your main cpp program
main.cpp
C++ Syntax (Toggle Plain Text)
#include<iostream> #include "myobj.h" using namespace std; int main() { some code return 0; }
Now compile the main.cpp. In g++ you compile with the compile only flag -c
C++ Syntax (Toggle Plain Text)
g++ -c main.cpp
C++ Syntax (Toggle Plain Text)
g++ -o mainProgram.exe main.o myobj.o
And you are done;
Note that you can avoid writing the myobj.h by directly declaring the prototype in your main program.
I hope it helps
Also note that your code of the myobj.o i.e myobj.c should not contain any c++ incompatible code. Also, the object file should have been of the same platform as your program(i.e. it should not been that you compiled the .obj file on a Unix and now try to link in a windows box)
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
•
•
•
•
siddhant3s, it seems your wonderful post does not bear a relation to the original question about Object-C/C++ mixture...
I thought he meant it as object files of C,
Anyways. I wasted typing so much
I guess someone would be helped while google indexes dani very efficiently!!!Its upto the moderator to do whatever with my post:
stupid me
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
![]() |
Similar Threads
- Not understanding Class Scope (C++)
- Abstract class homework problem (C++)
- Class Vectorization requirements (C++)
- Help figuring Obj. Oriented programing (C++)
- Compiling a Class in several parts?!? (C++)
- Which type of class is not instantiated? (Java)
- HELP writing structure and class definition - Visual C++ (C++)
- loop and class problem (C++)
- class polynomial (C++)
- Window class problem(iam a new bee) (Java)
Other Threads in the C++ Forum
- Previous Thread: Porting Unix,Linux sockets to windows without winsock
- Next Thread: Having problem to output the sum of cubes with sum of squares
Views: 331 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream input int integer java lazy lib linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets







...