Objective-C++ Instance Variables

Objective-C++ Instance Variables

Post by Jason » Fri, 04 Jul 2008 16:07:47


hi:

I'm trying to bridge between my Cocoa App and my C++ framework via
Objective-C++. Apparently I can't have C++ objects as instance
variables in my ObjC class because they contain virtual methods. Also,
I don't appear to be able to include my C++ header files in by ObjC
header file; they work fine if I include them in my implementation
file (.mm).

How should I create my C++ objects and use them within my ObjC class
(over it's lifetime)?

Perhaps I should be doing this a different way? What I have is a C++
framework compiled into a dylib. I include the headers in my .mm and
link in the dylib.
 
 
 

1. instance variable of class instance ( C extension: can rb_ivar_set be used to set class variable?)

2. Equivalent of C's "global/static" variables

I've not been doing Lisp for very long, and have a few questions about
global/static variables.
I think that I understand (defvar) variables, they are global and
special (dynamically scoped?). Reassigning them with LET is a
stack-like effect where they go back to their original value after the
let expires.
Lets say I have a simple application that draws a line 100 pixels long,
from a start point toward the mouse. If the mouse is more than 100
pixels away, the line moves toward the mouse. So when you move the
mouse the line mostly follows it.
For arguments sake, lets say I want to do this with 2 functions, UPDATE
and DRAW, which recalculates the line properties & draws it,
respectively. I will need some data that is shared between these two
functions to store the line points, lets say p1 and p2.

In a simple C app, I would probably just make these global variables.
I can do this with Lisp and DEFVAR, but the variables don't really need
to be special.

In C++ I might make a class, and pass that to the functions. I can do
this with CLOS, and long term it might be a good idea, but is probably
overkill here.

I am currently, in Lisp, surrounding both functions with a let:
(let ((p1 nil) (p2 nil))
(defun update (x y) ...)
(defun draw ()...))

The functions are simple and clean, the data is somewhat encapsulated,
though if I need to share the data widely later it might be a problem.
So, my question is - what is the Lispy way to do what I want to do?
Are there downsides to encapsulating multiple functions with a LET?
This all doesn't feel very functional either though (I am also new to
functional programming), is this an easy problem to solve in an FP way?

Cheers
Brad

3. lack of C's static local variables

4. Method equality; setting instance variables on Method instances

5. instance variables in objects retain values from previously created instances

6. How to change instance variable value in instance function

7. accessing class instance variable from instance method

8. including instance methods and setting an instance variable

9. Problem when subclass instance changes base class instance variable

10. Automation from Cocoa (Objective-C) App.

11. Objective-C FAQ

12. Access Filemaker Files via Objective-C 2.0/iPhone SDK

13. Java/Swing or Objective-C/Cocoa?

14. Nuby question on Class Variable and Class Instance Variable

15. Objective-C bindings for Scheme 48?