C++ 模板参数访问

C++ 模板参数访问,c++,oop,templates,c++11,generics,C++,Oop,Templates,C++11,Generics,假设我有两门课。第一个是简单模板类点,另一个是函数。是否可以访问类内函数以键入T和intN 这是我的观点,我认为没问题 template<int N, class T> class Point { public: Point() { std::fill(std::begin(data), std::end(data), T(0)); } Point(const std::initializer_list<T> &init)

假设我有两门课。第一个是简单模板类
,另一个是
函数
。是否可以访问类内函数以键入
T
和int
N

这是我的
观点
,我认为没问题

template<int N, class T>
class Point {
public:
    Point() {
        std::fill(std::begin(data), std::end(data), T(0));
    }

    Point(const std::initializer_list<T> &init) {
        std::copy(init.begin(), init.end(), std::begin(data));
    }

public: // just for easier testing, otherwise protected/private
    T data[N];
};
下面是我如何使用我的课程。也许我想得太多了,比如:)

typedef点3f;
类型定义点4f;
点3f pt3f({1.0,2.0,3.0});//指向
点4f pt4f({1.0,2.0,3.0,4.0});//指向
函数f3;//功能f3;
浮点值=f3(pt3f);//无误
浮点值=f3(pt3f,pt3f);//无误
浮点值=f3(pt4f);//编译错误
浮点值=f3(pt4f,pt3f);//编译错误
我怎样才能做到这样的行为?我不断遇到错误,比如
“Point”不是类模板
,或者
类模板“Function”的参数太少

模板
类函数;
模板
类函数
取代:

template<template<int, typename> class P, int N, typename T>
class Function
模板
类函数

解决您的语法问题。

谢谢您的帮助。现在工作。我感到震惊,这是不可能的。
typedef Point<3, float> Point3f;
typedef Point<4, float> Point4f;

Point3f pt3f({ 1.0, 2.0, 3.0 });       // Point<3, float>
Point4f pt4f({ 1.0, 2.0, 3.0, 4.0 });  // Point<4, float>

Function<Point3f> f3;         // Function<Point<3, float>> f3;

float val = f3(pt3f);         // no error
float val = f3(pt3f, pt3f);   // no error
float val = f3(pt4f);         // compile error
float val = f3(pt4f, pt3f);   // compile error
template<class Point>
class Function;

template<template<int, typename> class P, int N, typename T>
class Function<P<N,T>>
template<template<int, typename> class P, int N, typename T>
class Function