小编h20*_*man的帖子

我应该如何在我的C++项目中声明全局变量?

我有两个矩阵作为全局变量.但是,当我运行我的项目时,我在xCode中得到一个apache Mach-O链接器错误,该错误表明我的全局变量被多次声明.我已确定问题是我的全局变量的放置和头文件的导入.

我的svd.h在这里:

#ifndef __netflix_project__svd__
#define __netflix_project__svd__

#include <stdio.h>
#include "dataManager.h"

const float GLOBAL_AVG_SET1 = 3.608609;
const float GLOBAL_AVG_SET2 = 3.608859;

const int TOTAL_USERS = 458293;
const int TOTAL_MOVIES = 17770;

double **user_feature_table = new double *[TOTAL_USERS];
double **movie_feature_table = new double *[TOTAL_MOVIES];


void initialize(int num_features);
void train();
double predictRating(int user, int movie); 




#endif /* defined(__netflix_project__svd__) */
Run Code Online (Sandbox Code Playgroud)

我的svd.cpp在这里:

#include "svd.h"



void initialize(int num_features) {

    for(int i = 0; i < TOTAL_USERS; i++) {

        user_feature_table[i] = new double[num_features];

        for(int k = …
Run Code Online (Sandbox Code Playgroud)

c++ global-variables include header-files

2
推荐指数
1
解决办法
4540
查看次数

标签 统计

c++ ×1

global-variables ×1

header-files ×1

include ×1