locked
What does this error mean, despite that the program compiled successfully? RRS feed

  • Question

  • This is the screenshot of the program's error code.

    This is the source code:

    #include <iostream>
    #include <memory>
    using namespace std;
    
    class Base {
    public:
    	virtual shared_ptr<Base> clone() const = 0;
    };
    
    class Special : public Base {
    	int someNumber;
    	void* dangerousPointer;
    public:
    	Special(const Special& other) : someNumber{ other.someNumber } {
    		// TODO: clone dangerous pointer if such thing exists
    	};
    	Special(int someNumber) : someNumber{ someNumber } {
    	}
    
    	int getSomeNumber() {
    		return someNumber;
    	}
    	virtual shared_ptr<Base> clone() const override {
    		return make_shared<Special>(*this);
    	}
    };
    
    
    
    int main() {
    	shared_ptr<Base> b{ make_shared<Special>(42) };
    	shared_ptr<Base> other = b->clone();
    
    	if (dynamic_cast<Special*>(other.get()) != nullptr){
    		cout << dynamic_cast<Special*>(other.get())->getSomeNumber() << endl;
    	}
    	else {
    		cout << "Null ptr found." << endl;
    	}
    
    
    	cout << endl << endl << "This is compiled successfully." << endl;
    	system("pause");
    	return 0;
    }

    What does the error mean? Thanks.

    Monday, July 25, 2016 9:20 PM

Answers

  • It means that Intellisense incorrectly detected an error.

    Intellisense frequently doesn't have 100% correct information (for various reasons) and because of that often reports false positives on errors.  (I find it annoying enough that I turn off Intellisense errors in my Error List).

    The Compiler has the final say.  If the Compiler says your code is good then it is.

    • Marked as answer by tom_mai78101 Monday, July 25, 2016 9:34 PM
    Monday, July 25, 2016 9:29 PM

All replies

  • It means that Intellisense incorrectly detected an error.

    Intellisense frequently doesn't have 100% correct information (for various reasons) and because of that often reports false positives on errors.  (I find it annoying enough that I turn off Intellisense errors in my Error List).

    The Compiler has the final say.  If the Compiler says your code is good then it is.

    • Marked as answer by tom_mai78101 Monday, July 25, 2016 9:34 PM
    Monday, July 25, 2016 9:29 PM
  • Ok, so I assumed correctly IntelliSense is wrong.

    I'll be reporting this error to Microsoft Connect.

    Thanks for the info!

    Monday, July 25, 2016 9:34 PM