1

There is nothing wrong with static methods of template classes having (i) templates and (ii) the class itself as a parameter, is there? Consider the class

template<class Projection>
struct FrameData {
    // ...
    template <bool devPtr>
    static void allocate(FrameData<Projection> &data) {
        // ... do allocations ...
    }

}

This is declared in the header of file A. Elsewhere in the world, I have something like

template <class Projection>
void some_method(FrameData<Projection> &m_data) {
    FrameData<Projection>::allocate<true>(m_data);
}

I'm ending up with some

error: reference to overloaded function could not be resolved; did you mean to call it?
  • Is there some sort of analagous .template magic for static methods like the answer here?
  • Is the parameter FrameData<Projection> the problem? It isn't fully defined yet?

Elsewhere in this world is technically in a source file with some explicit instantiations going on at the bottom, but I put this all in one file with the same errors. Thank you for any insight, please refrain from shaming me on non-header templates. It wasn't my choice.

svenevs
  • 833
  • 9
  • 24
  • 1
    Such API seems backwards to me, at least in choice of name. You cannot "allocate" an object you were passed by reference, it must already exist, i.e. be allocated. – StoryTeller - Unslander Monica Jun 11 '17 at 10:54
  • Yeah I shortened the names and removed the majority of the definitions. It's a wrapper struct that houses pointers to host / device data – svenevs Jun 11 '17 at 10:57
  • 1
    This is fine except for the `::template` detail already answered. Maybe the real source has a good reason, but it's not clear why you're taking a parameter of the same type in a `static` function rather than using an implicit parameter: `template void allocate();` – aschepler Jun 11 '17 at 11:04
  • Oh I see what you both are getting at. I don't think I do have a justification for that. I think it became this way because this was originally translated from `C`, so your standard `make_struct` type thing probably just got thrown into the class. I completely agree though, I'll have to change that (now that I am actually able to compile it xD) – svenevs Jun 11 '17 at 11:42

1 Answers1

7

Is there some sort of analagous .template magic for static methods like the answer here?

Yes.

template <class Projection>
void some_method(FrameData<Projection> &m_data) {
    FrameData<Projection>::template allocate<true>(m_data);
}
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
  • AhHhHHHhhhh WOW I can't believe I never tried that. Thank you, will accept as soon as the 12 minute window has passed. – svenevs Jun 11 '17 at 10:56