C++ errors with Graham Wakefield's template

derp mcderpington's icon

Hey y'all. trying to compile the C++ example from Graham Wakefield using Visual Studio on windows (I'd use my mac but the whole point is to port a windows program), and i'm getting 2 errors:

Example.cpp(3) : error C2955: 'MaxCpp5' : use of class template requires template argument list

also,

MaxSDK-5.1.1c74supportMaxCPP5maxcpp5.h(91) : see declaration of 'MaxCpp5'

line 91 from maxcpp5.h is

class MaxCpp5 : public MaxCppBase {

anyone seen these errors or have an idea how to fix it? thanks.

the entire code:

#include "maxcpp5.h"

class Example : public MaxCpp5 {
public:
    Example(t_symbol * sym, long ac, t_atom * av) {
        setupIO(2, 2); // inlets / outlets
        post("created an example");
    }
    ~Example() { post("freed an example"); }    

    // methods:
    void bang(long inlet) {
        post("bang in inlet %i!", inlet);
        outlet_bang(m_outlet[0]);
    }
    void test(long inlet, t_symbol * s, long ac, t_atom * av) {
        post("%s in inlet %i (%i args)", s->s_name, inlet, ac);
        outlet_anything(m_outlet[1], gensym("test"), ac, av);
    }
};

extern "C" int main(void) {
    // create a class with the given name:
    Example::makeMaxClass("example");
    REGISTER_METHOD(Example, bang);
    REGISTER_METHOD_GIMME(Example, test);
}

derp mcderpington's icon

I should mention im using Visual Studio 2008.

Graham Wakefield's icon

hi

I just tried building the example on Visual Studio 2008 - it works for me.

I think I know what the problem is: your class needs to inherit from MaxCpp5 with a template parameter (which is the class name, in the 'curiously recurring template' pattern); that is, like this:

class Example : public MaxCpp5 {

I just noticed that the example code on my webpage didn't display this properly, because the angle brackets were treated as HTML tags. I just fixed it.

I've just updated the archive to include a Visual C++ 2008 solution file for the examples.

HTH

derp mcderpington's icon

thanks for the fix, Graham!