我有一個Eclipse Indigo的問題,抱怨類的方法無法解析,但無論如何編譯並正常工作(AFAIK)。這是一個非常簡單的程序。這裏是Population.cpp:Eclipse方法無法在簡單程序中解決C++
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include "Population.h"
Population::Population() {
// TODO Auto-generated constructor stub
}
Population::~Population() {
// TODO Auto-generated destructor stub
}
void Population::initializePop(int numBits, int N) {
srand((unsigned)time(0));
for(int i=0; i<N; i++) {
x[i] = (char*) calloc(numBits, sizeof(char));
for(int j=0; j<numBits; j++) {
if(rand() < 0.5)
x[i][j] = 0;
else
x[i][j] = 1;
}
}
}
char** Population::getX() {
return x;
}
void Population::printStuff() {
std::cout << "Whatever";
}
現在,我建立的代碼,一切都很好。在Eclipse中的另一個項目,我打電話這段代碼是這樣的:
#include <typeinfo>
#include <string.h>
#include <iostream>
#include "cute.h"
#include "ide_listener.h"
#include "cute_runner.h"
#include "Population.cpp"
void testPopulationGeneration() {
Population* p = new Population;
int N = 10;
int bits = 4;
char** pop;
ASSERTM("Population variable improperly initialized", dynamic_cast<Population*>(p));
std::cout << p->printStuff();
std::cout << "Ok...";
p->initializePop(bits, N);
pop = p->getX();
ASSERTM("Pop not correct size.", sizeof(pop) == 10);
}
正如你看到的,我也運行TDD可愛的插件在C++中。當我將p聲明爲類型Population並且第一個斷言通過時,它不會抱怨。我對C++有點新鮮,但確實要將Population.cpp所在的項目添加到測試項目的包含路徑中。
這不是一個大問題,因爲它不會影響任何對我來說很明顯的事情,但它仍然非常煩人。我沒有看到它應該這樣做的情況。
感謝您的幫助!
謝謝你的提示!它沒有回答這個問題,但是提示的大小幫助我解決了問題。我想我一直在使用高級語言太久了。像這樣的基礎上生鏽了一點。它幾乎看起來像是一個黑客,只是將大小和數組本身一起存儲,但我猜如果數組的大小將作爲命令行輸入,那麼在C++中沒有更好的方法。 – 2012-02-03 16:33:23