我有一个class A具有std::vector<int>作为属性.
A在A创建实例时需要填充此向量.计算可能需要一些时间,我想知道是否:
我不熟悉元编程,我现在找不到办法.这不是特定于操作系统的问题.
这是A.cpp文件:
#include "A.h"
#define SIZEV 100
A::A()
{
fillVector();
}
void A::fillVector()
{
// m_vector is an attribute of class "A"
// EXPECTATION 1 : fill the vector with the following calculation at compile time
const int a=5;
const int b=7;
const int c=9;
for(int i=0;i<SIZEV;i++){
for(int j=0;j<SIZEV;j++){
for(int k=0;k<SIZEV;k++){
this->m_vector.push_back(a*i+b*j+c*k);
}
}
}
// EXPECTATION 2 : sort the vector as compile time
} …Run Code Online (Sandbox Code Playgroud)