-
December 26th, 2010, 05:50 PM
#1
Problem with explicit instantiation
Hi template gurus:
Using MS V2008 I found a problem that I'm unable to surmount. Here is a minimal reconstruction:
// header.h
#pragma once
#include <map>
struct pXXX {
std::string p1_;
std::string p2_;
std::string p3_;
};
std::map <std::string, pXXX> xMAP;
std::map<std::string, pXXX>::iterator itXXX;
#define FNAM(flag) (#flag, oxxx)
#define XXX_2(R,N,A,B)\
template <typename R, typename A, typename B> struct X_2 {\
pXXX oxxx;\
X_2 () {\
oxxx.p1_ = typeid(R).name();\
oxxx.p2_ = typeid(A).name();\
oxxx.p3_ = typeid(B).name();\
itXXX = xMAP.begin();\
xMAP.insert (itXXX, std:air<std::string, pXXX> FNAM(N));\
}\
};
// main.cpp
#include <iostream>
//#include <conio.h>
//#include <iomanip>
#include <sstream>
#include "cabecera.h"
// XXX_2(int,name,int,int) // L.1
template <typename R, typename A, typename B> struct X_2 { // L.2
pXXX oxxx;
X_2 () {
oxxx.p1_ = typeid(R).name();
oxxx.p2_ = typeid(A).name();
oxxx.p3_ = typeid(B).name();
itXXX = xMAP.begin();
xMAP.insert (itXXX, std:air <std::string, pXXX>("name", oxxx));
}
}; // */
int main () {
X_2 <int, int, int> x2; // M.L.1
std::cout << "\nPress Enter to exit..." << std::endl;
std::cin.get();
return 0;
}
As is, the program compiles and run Ok, but when commenting the template definition of L.2 and uncommenting the L.1, who suposedly produces the same definition (see header.h), the compiler shown an error in M.L.1: "error C2975: 'X_2' : invalid template argument for 'unnamed-parameter', expected compile-time constant expression".
The question is: ¿Are there some way to do that? Any suggestion would be wellcome.
Thanks in advance.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|