olidev
olidev

Reputation: 20644

C++: Error: Unable to create variable object

I have a simple method:

std::vector<string> start()
{
    std::vector<std::string> deletedFiles; // << error appeared at this declaration
}

Error: Unable to create variable object

What is wrong here?

Thanks in advance.

Upvotes: 2

Views: 10092

Answers (3)

Roddy
Roddy

Reputation: 68033

Maybe you've missed a namespace prefix...

std::vector<string> start()

Should it be this?

 std::vector<std::string> start()

Upvotes: 0

Magnus Hoff
Magnus Hoff

Reputation: 22089

This similar program compiles without a hitch:

#include <vector>
#include <string>

std::vector<std::string> start()
{
    std::vector<std::string> deletedFiles;
    return deletedFiles;
}

int main()
{
    std::vector<std::string> deletedFiles = start();
    return 0;
}

Please double check your #includes and your std::s. You might want to add std:: to string in your return type.

Upvotes: 4

MSalters
MSalters

Reputation: 179799

Nothing, really. The error will be somewhere else. For instance, there's a missing return statement in the function, and you're missing #include's, but that's probably code you snipped.

Upvotes: 0

Related Questions