I created a function template that includes a configuration struct
. I define some constants in this structure, and I want to include a couple of static arrays
. Here, I am trying to reduce the number of input parameters for the function call.
Here is a code snippet that can show my error:
// parameters.h file
#ifndef PARAMETERS_H
#define PARAMETERS_H
struct config_1 : k_config {
static const unsigned n_in = 16;
static const unsigned n_out = 32;
static const unsigned g_dim = 10;
float g_d1[g_dim] = {-3.0, -2.3333333, -1.6666666, -1.0, -0.33333325, 0.3333335, 1.0, 1.666667, 2.3333335, 3.0};
};
#endif
//foo.h file
#ifndef KAN_DENSE_H_
#define KAN_DENSE_H_
#include "utils.h"
struct k_config {
// Layer sizes
static const unsigned n_in;
static const unsigned n_out;
static const unsigned g_dim = 10;
float g[g_dim];
};
template <typename T, typename CONFIG_T>
void foo(T x_in[CONFIG_T::n_in], T x_out[CONFIG_T::n_out]) {
T tmp1[CONFIG_T::n_in];
foo_fun1<T, CONFIG_T::n_in>(x_in, tmp1);
T tmp2[CONFIG_T::n_in][CONFIG_T::n_out];
foo_fun2<T, CONFIG_T>(x_in, CONFIG_T::grid, tmp2);
}
#endif
Finally in make this main file to test :
#include <stdio.h>
#include "kan_dense.h"
#include "parameters.h"
int main() {
float x_in[16] = {-0.11950312f, 0.40616292f, -1.04058613f, -0.82473132f, -0.75533621f, -0.58097338f,
1.98691601f, 1.53806275f, 1.98691601f, 0.6312378f, 0.38356148f, -0.20130531f,
1.05976638f, 0.40865762f, -1.01995561f, -0.18016747f};
float x_out[16];
k_dense<float, config_d1>(x_in,x_out);
printf("Done!");
return 0;
}
Error: undefined reference to config_1::g_d1. Could someone explain toi me why ?