相关主题: 为什么const在C ++中表示内部链接而在C ++中却没有?
我正在关注GCC可见性Wiki,以将可见性添加到共享库中。
当我编译源文件时,它会生成警告
警告:“可见性”属性已忽略[-Wattributes]
这是我的代码:
// my_shared_lib.h
#if __GNUC__ >= 4
#define DLL_API __attribute__((visibility("default")))
#define DLL_LOCAL __attribute__((visibility("hidden")))
#else
#define DLL_API
#define DLL_LOCAL
#endif
DLL_LOCAL const int my_local_var;
Run Code Online (Sandbox Code Playgroud)
编译时会产生以下警告:
my_shared_lib.h: 'visibility' attribute ignored [-Wattributes]
DLL_LOCAL const int my_local_var;
^
Run Code Online (Sandbox Code Playgroud)
这是整个建筑物的信息:
make all
Building file: ../src/my_shared_lib.cc
Invoking: Cross G++ Compiler
g++-mp-4.8 -O3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/my_shared_lib.d" -MT"src/my_shared_lib.d" -o "src/my_shared_lib.o" "../src/my_shared_lib.cc"
my_shared_lib.h: 'visibility' attribute ignored [-Wattributes]
DLL_LOCAL const int my_local_var;
^
Finished building: ../src/my_shared_lib.cc
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何使此警告静音以及为什么发生此警告? …
我需要在我的程序中找到不同维度(将是1维,2维和最多N维数组)的数组的最大值和最小值.
谁能帮我写一个函数或函数模板,可以输入任意维数组并找到最大/最小值?*我正在使用矢量矢量这样的东西:
#include <vector>
<template T>
int find_max(T target_array, int dimension);
int main() {
using namespace std;
vector<int> array_1d = {1,3,4};
vector<vector<int> array_2d = {{1,3},{3,5,2},{6,4}};
vector<vector<vector<int>>> array_3d = {{{1,3},{2,4,5}},{{6,7,2,3}}};
cout << "Max in 1d array: " << find_max<vector<int>>(array_1d, 1) << endl;
cout << "Max in 2d array: " << find_max<vector<vector<int>>(array_2d, 2) << endl;
cout << "Max in 3d array: " << find_max<vector<vector<vector<int>>>>(array_3d, 3) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
Max in 1d array: 4
Max in 2d array: 6
Max …
Run Code Online (Sandbox Code Playgroud)