Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

c++ - Eclipse Method无法在简单的程序C ++中解决(Eclipse Method could not be resolved in a simple program C++)

I have an issue with Eclipse Indigo complaining that methods of a class couldn't be resolved, but compiling anyway and working correctly (AFAIK).

(我对Eclipse Indigo遇到问题,抱怨无法解决类的方法,但是无论如何还是可以编译并且可以正常工作(AFAIK)。)

It's a very simple program.

(这是一个非常简单的程序。)

Here is Population.cpp:

(这是Population.cpp:)

#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";
}

Now, I build that code and everything is fine.

(现在,我构建该代码,一切都很好。)

In another project within Eclipse, I'm calling this code like this:

(在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);
}

As you can see I'm also running the CUTE plugin for TDD in C++.

(如您所见,我还在C ++中运行TDD的CUTE插件。)

It doesn't complain when I declare p as type Population and the first assertion passes.

(当我将p声明为“人口”类型并且第一个断言通过时,它不会抱怨。)

I'm somewhat new to C++, but I did make sure to add the project that Population.cpp is from to the include path for the test project.

(我是C ++的新手,但我确实确保将“ Population.cpp”所在的项目添加到测试项目的包含路径中。)

It's not a huge deal as it's not affecting anything obvious to me, but it's still very annoying.

(这并没有什么大不了的,因为它并没有影响到任何对我来说显而易见的东西,但是仍然很烦人。)

I don't see a situation where it should do this.

(我看不到应该这样做的情况。)

Thanks for any help!

(谢谢你的帮助!)

  ask by F_C translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

(尝试这个:)

In your project explorer window, right click on your project -> Index -> Rebuild

(在项目资源管理器窗口中,右键单击项目->索引->重建)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...