【问题标题】:C++ Error no matching function for call to static template methodC++ 错误没有匹配函数调用静态模板方法
【发布时间】:2017-02-24 05:44:16
【问题描述】:

我试图从另一个类调用静态方法,但是当我运行它时,它会抛出这个:

PagedArray.cpp:21:37: error: no matching function for call to ‘FileManager::loadPage(int&)’
page = FileManager::loadPage(index);

这是我尝试调用它的代码:

PagedArray.cpp

#include "PagedArray.h"
#include "../Entidades/FileManager.h"


template <typename T>
int* PagedArray<T>::operator[](int index) {

Page<T>* page = nullptr;

for(int i = 0; i < this->pagesQueue->Size(); i++){
    if(index == ( *(this->pagesQueue->get(i)->getDato()) )->getLineaActual()){
        page = *this->pagesQueue->get(i)->getDato();
    }
}

if(page == nullptr){
    page = FileManager::loadPage(index); //This is the problem
}
return page->getInfo()->get(index)->getDato();

}

这是 FileManager 类:

文件管理器.h

#include "../Estructuras/Page.h"


class FileManager {

public:

FileManager();

template <typename T>
static Page<T>* loadPage(int index);
};

文件管理器.cpp

#include "FileManager.h"

FileManager::FileManager(){}

template <typename T>
Page<T>* FileManager::loadPage(int index) {
    Page<T>* page = nullptr;
    return page ;
}

loadPage 方法中的主体只是为了进行测试,所以我认为它并不真正相关。 对不起,如果我错过了什么,这是我第一次来这里,所以如果您需要其他东西,请在下面留下

【问题讨论】:

    标签: c++ templates compiler-errors static-methods


    【解决方案1】:

    FileManager::loadPage是一个函数模板,它有一个不能自动推导的模板参数。所以你必须明确指定它。例如

    page = FileManager::loadPage<T>(index);
    //                          ~~~
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 2016-01-18
      • 2012-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多