Click here to Skip to main content
16,016,022 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: console app which handle windows events Pin
Victor Nijegorodov2-Feb-18 4:07
Victor Nijegorodov2-Feb-18 4:07 
AnswerRe: console app which handle windows events Pin
Jochen Arndt2-Feb-18 0:23
professionalJochen Arndt2-Feb-18 0:23 
AnswerRe: console app which handle windows events Pin
leon de boer4-Feb-18 13:42
leon de boer4-Feb-18 13:42 
Questionriver crossing priests and devils in c program Pin
Member 1365554231-Jan-18 23:14
Member 1365554231-Jan-18 23:14 
AnswerRe: river crossing priests and devils in c program Pin
Richard MacCutchan31-Jan-18 23:21
mveRichard MacCutchan31-Jan-18 23:21 
AnswerRe: river crossing priests and devils in c program Pin
jeron11-Feb-18 3:19
jeron11-Feb-18 3:19 
QuestionRe: river crossing priests and devils in c program Pin
David Crow1-Feb-18 3:47
David Crow1-Feb-18 3:47 
QuestionC++ - Static templated method inside a class Pin
phil.o31-Jan-18 12:00
professionalphil.o31-Jan-18 12:00 
So, I finally decided to dive into C++ world, trying to adapt some C# code I've been working on lately.
So here's what I have.
bin.h file:
C++
#pragma once

namespace Maths {

   class Bin
   {
      public:
         template <class T> static const T GetMask(int);
   };

}

bin.cpp file:
C++
#include "bin.h"

namespace Maths {

   template <class T> const T Bin::GetMask(int count) {
      return (T)0; // Fake implementation
   }

}

This compiles just fine. However, in the same console project, when I write:
C++
#include "bin.h"

using namespace Maths;

int main() {
   unsigned char value = Bin::GetMask<unsigned char>(0);
}

I get a nasty LNK2019 linkage error on compilation:
Error	LNK2019	unresolved external symbol "public: static unsigned char const __cdecl Maths::Bin::GetMask<unsigned char>(int)" (??$GetMask@E@Bin@Maths@@SA?BEH@Z) referenced in function "int __cdecl main(void)" (?main@@YAXXZ)

In the Bin class, I have a couple of other (non-generic) methods, which I can use just fine. I suspect a problem with static templated methods specifically, but I can't understand the core problem. Maybe I just try to do something which is not possible (using a static generic method), but I cannot figure out why it would not be possible.

Anyone could give me a hint on this?
"I'm neither for nor against, on the contrary." John Middle

AnswerRe: C++ - Static templated method inside a class Pin
Richard MacCutchan31-Jan-18 12:13
mveRichard MacCutchan31-Jan-18 12:13 
GeneralRe: C++ - Static templated method inside a class Pin
phil.o31-Jan-18 13:28
professionalphil.o31-Jan-18 13:28 
GeneralRe: C++ - Static templated method inside a class Pin
Richard MacCutchan31-Jan-18 21:41
mveRichard MacCutchan31-Jan-18 21:41 
GeneralRe: C++ - Static templated method inside a class Pin
phil.o31-Jan-18 14:07
professionalphil.o31-Jan-18 14:07 
GeneralRe: C++ - Static templated method inside a class Pin
CPallini31-Jan-18 21:20
mveCPallini31-Jan-18 21:20 
GeneralRe: C++ - Static templated method inside a class Pin
Richard MacCutchan31-Jan-18 21:48
mveRichard MacCutchan31-Jan-18 21:48 
GeneralRe: C++ - Static templated method inside a class Pin
phil.o1-Feb-18 3:20
professionalphil.o1-Feb-18 3:20 
GeneralRe: C++ - Static templated method inside a class Pin
Richard MacCutchan1-Feb-18 4:08
mveRichard MacCutchan1-Feb-18 4:08 
QuestionExplorer Pin
Fedrer31-Jan-18 0:12
Fedrer31-Jan-18 0:12 
AnswerRe: Explorer Pin
Richard MacCutchan31-Jan-18 0:49
mveRichard MacCutchan31-Jan-18 0:49 
AnswerRe: Explorer Pin
Jochen Arndt31-Jan-18 1:22
professionalJochen Arndt31-Jan-18 1:22 
AnswerRe: Explorer Pin
Randor 31-Jan-18 5:26
professional Randor 31-Jan-18 5:26 
QuestionSize of a window Pin
Anthony Appleyard29-Jan-18 5:05
Anthony Appleyard29-Jan-18 5:05 
AnswerRe: Size of a window Pin
OriginalGriff29-Jan-18 5:07
mveOriginalGriff29-Jan-18 5:07 
AnswerRe: Size of a window Pin
Victor Nijegorodov29-Jan-18 10:49
Victor Nijegorodov29-Jan-18 10:49 
GeneralRe: Size of a window Pin
Anthony Appleyard31-Jan-18 5:56
Anthony Appleyard31-Jan-18 5:56 
GeneralRe: Size of a window Pin
Richard MacCutchan31-Jan-18 6:05
mveRichard MacCutchan31-Jan-18 6:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.