Quote Originally Posted by Singing Boyo View Post
The code is long as it is part of a mini-compiler (tracking variable names) but here are the exact methods being used.

Also, sorry for the bad terminology - I'm more of a java person, so to me, everything is an object

the code that needs a pointer to create the pointer to the this pointer...

Code:
PostInitObject::PostInitObject(PType type)
        //PObject is a typedef for PostInitObject
    List<PObject*>* tlist = postInits->data2For(type);
        PObject** ptrtothis = &this;//non-lvalue in unary '&'
        //I also tried almeto's way of doing things, and it caused the program to crash
        //this is the only source of errors in the program at this point - it is this call that fails if
        //I use almeto's idea
    tlist->add(ptrtothis);
And the add method for the list, though I don't believe it has any problems.
Code:
TEMPLT void List<t>::add(const t* obj, int len){//len is 1 by default
    if(totalSize-objectCount>len){
        for(int i=0; i<len; i++){
            contents[i+objectCount] = obj[i];
        }
    }else{
        increaseSize(len);
        for(int i=0; i<len; i++){
            contents[i+objectCount] = obj[i];
        }
    }
    objectCount+=len;
}
and here are the full class declarations, just in case
Code:
class Variable:public PostInitObject{
    static List<string>* nameList;
    static PType vartype;//type of the variable in assembly terms
public:
    Variable();
    Variable(string name, VariableType abbrevtype) throw(Duplicate);
    void postInit();
    void writeSizedRef();
    virtual ~Variable();
private:
    string name;
    VariableType type;
    friend void initParser();
    friend void endParser();
    static void sInit();
    static void sClose();
};
 
template<class t> class List{
    t* contents;
    int objectCount, totalSize, id;
    static int UID;
protected:
    t* copy(int& length);
    void increaseSize(int amt);
public:
    List();
    List(t* contents, int length);
    List(int listlength);
    List(t* contents, int length, int additionalLength);
    ~List();
    t* at(int index);
    /* Removes the specified index from this list.
     * Note that if the given index is greater than the
     * number of objects in the List, the given index
     * will be modified to the last index in the last, and
     * the last index in the list will be removed.
     */
    t remove(int& index);
    bool remove(t obj);
    bool contains(t obj);
    void add(const t* object, int length=1);
    void insert(int index, const t* object,int length=1);
    int size(){return objectCount;}
    bool operator == (List<t> lst){return lst.id==id;}
private:
//these are left undefined - lists cant be copied
    List(const List<t>& c);
    bool operator=(const List<t>& c);
};
In this code, where do you use 'this' or where would you like to?