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?
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.