-1

I am binding a class to squirrel and I have come across a problem I don't know how to resolve. The class has a function which takes another class as an argument. When I choose not to bind that specific function it compiles, but when I do it throws an error.

Classes:

class A
{
    public:
        A(int foo) : m_foo(foo) {}

    private:
        int m_foo;
}

class B
{
    public:
        void bar(A foo) { /* Do Stuff with foo */ }
}

Bindings

Sqrat::RootTable().Bind("A", Sqrat::Class<A>());

Sqrat::RootTable().Bind("B", Sqrat::Class<B>())
    .Func("bar", &B::bar);
);

The class that is used as an argument has already been bound to squirrel with Sqrat with no problems however it seems Sqrat still can't recognise what type it is. Any ideas as to why this is occurring?

Semirix
  • 271
  • 3
  • 13

1 Answers1

1

The problem was that the argument in the function needed to be passed as a reference like this:

class B
{
    public:
        void bar(A &foo) { /* Do Stuff with foo */ }
}

The reason this was a problem was because the object that was passed as an argument required an argument in it's constructor. Sqrat tries to create and instance of the class before copying the values over from the arguments. Making the argument a reference to the object stopped Sqrat from trying to instantiate an invalid object with no arguments.

Semirix
  • 271
  • 3
  • 13
  • You really needed sample code in your question. From your answer, obvioiusly no one could have helped with this. – djechlin Jul 01 '14 at 14:22
  • I have edited the question and the answer so that this may be useful to future visitors. Please remove the downvotes so future visitors aren't discouraged from reading this – Semirix Jul 05 '14 at 08:33
  • I wish downvoters would at least comment as to why they have done so – Semirix Jul 06 '14 at 06:05