【发布时间】:2015-03-02 14:50:38
【问题描述】:
我有一个类,我想包含来自另一个类CRandomSFMT 的对象(我自己没有编写)。这是test.h:
using namespace std;
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include "sfmt.h"
class Something {
public:
Something();
private:
int seed;
CRandomSFMT rangen();
void seed_generator(int, CRandomSFMT&);
};
这是test.cpp:
#include "test.h"
Something::Something() {
seed=1;
seed_generator(seed, rangen);
}
void Something::seed_generator(int seed, CRandomSFMT& rangen) {
rangen.RandomInit(seed);
}
当我尝试用 g++ -c sfmt.o -msse2 -std=c++11 -O2 test.cpp 编译它时,我得到了
test.cpp: In constructor ‘Something::Something()’:
test.cpp:5:30: error: invalid use of non-static member function
seed_generator(seed, rangen);
我尝试声明 seed_generator() 静态,但这没有帮助。这是CRandomSFMT类的声明:
class CRandomSFMT {
public:
CRandomSFMT(int seed, int IncludeMother = 0) {
UseMother = IncludeMother;
LastInterval = 0;
RandomInit(seed);}
void RandomInit(int seed);
void RandomInitByArray(int const seeds[], int NumSeeds);
int IRandom (int min, int max);
int IRandomX (int min, int max);
double Random();
uint32_t BRandom();
private:
void Init2();
void Generate();
uint32_t MotherBits();
uint32_t ix;
uint32_t LastInterval;
uint32_t RLimit;
uint32_t UseMother;
__m128i mask;
__m128i state[SFMT_N];
uint32_t MotherState[5];
};
有什么想法吗?
【问题讨论】:
标签: c++ class constructor static