我做错了什么?奇怪,因为构造函数的签名是相同的。编译器说: ' ShaderProgram :: ShaderProgram(std :: vector< int *,std :: allocator< _Ty>>)':在#ShaderProgram'中找不到重载的成员函数。 当我使用带有代码的3个文件(下面)时,会发生此错误,但是当我将此代码放在1个文件(主要cpp)中时 - 它可以正常工作
//main.cpp
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include "ShaderHelpers.h"
int main(int argc, const char* argv[]) {
int* a = new int(5);
int* b = new int(7);
ShaderProgram *sp = new ShaderProgram(std::vector<int*>{ a, b});
return 0;
}
================================================================
//shader.cpp
#include "ShaderHelpers.h"
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <string>
ShaderProgram::ShaderProgram() { }
ShaderProgram::ShaderProgram(std::vector<int*> shaders)
{
Shaders = shaders;
for each (int* i in shaders)
{
std::cout << i;
}
}
ShaderProgram::~ShaderProgram()
{
std::cout << "delete";
}
===============================================================
//ShaderHelper.h
#pragma once
#include <string>
class ShaderProgram
{
public:
std::vector<int*> Shaders;
ShaderProgram(std::vector<int*> shaders);
~ShaderProgram();
private:
ShaderProgram();
};
答案 0 :(得分:0)
我只需要添加
# include <vector>
进入ShaderHelper.h