简体   繁体   中英

Netbeans 7.3 highlights false errors C++

I installed the updates Netbeans 7.3 wanted me to yesterday, and I'm running Ubuntu 12.04. Now, when I create a new project, netbeans highlights a lot of errors in my code, but when I build, it compiles and runs with no errors.

Here's a simple example where I added the errors netbeans claims the code has in the comments.

main.cpp

#include <cstdlib>
#include <string>
#include <stdio.h>
#include "hello.h"
using namespace std;

int main()
{
    string s="hello";
    printf("%i\n",s.length()); //Unable to resolve identifier length
    hello h(0,0,0); //unable to resolve identifier hello
    printf("%i\n",h.z); //unable to resolve identifier z
    return 0;
}

hello.h

#ifndef HELLO_H
#define HELLO_H
class hello
{
public: //unexpected token: :
    int x;
    int y;
    int z;
    hello(int px,int py,int pz);
}; //unexpected token: }
#endif  

hello.cpp

#include "hello.h"
hello::hello(int px, int py, int pz) //method hello does not have declaration
{
    x=px;
    y=py;
    z=pz;
}

I tried compiling, cleaning and rebuilding, restarting netbeans, and making this in a new project, and nothing works. Any ideas?

Thanks in advance for your help :)

I had this same problem once. I needed to delete the user cache under {userdir}/var/cache/index

I found the bug report where this came from here:

https://netbeans.org/bugzilla/show_bug.cgi?id=153158

I reinstalled netbeans, which fixed most of the problems, and the rest went away when I spent a while removing the files from the project and then adding them back. Checking the file's properties and ensuring they were set to be compiled with c++ and not c also helped. Hopefully this problem won't come back to haunt me again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM