0

我正在 Visual Studios 2008 中进行 c++ 移植/开发。我遇到了以下问题。

1) 不允许可变大小的数组。2) 类的任何未定义函数的链接错误,即使它们没有被引用。(错误 LNK2001:未解析的外部符号“public:virtual void __thiscall ...)

我认为这些都与c++语言VS2008支持的版本有关。

我正在尝试编译和链接大型 c++ 代码库。我不能用 new/alloc 替换可变大小的数组。请给我解决方案,以便我可以使用现有代码。

谁能帮我解决这个问题?

但是下面的代码在同一个VS2008中工作正常

class Hello
{
public:
    int a;
public:
virtual void add();
};
class bye : public Hello
{
public:
    int y;
public:
    void add();
};

int main()
{
    std::cout << "got";
}

我哪里错了?

4

2 回答 2

1

Virtual functions are considered "used" if you have a single instance of a class created anywhere. Your link error indicate that certain virtual functions are not implemented. As the error list all of them by name it must be a trivial task to locate them, end figure out if you failed to include some code, compiled with different options, or they were indeed unimplemented in the source place -- in which case you can just add blank implementations calling terminate.

For the VLA problem: that extemsion is not present in VS2008, period. Even if you wait some years and VS201y will implement the new VLA-like thing in C++14, it will not go back to your chosen compiler. (kinda weird if you ask me to chose a 5-year old bug-ridden beast that has dropped of support long ago, instead of the current...)

But std::vector does almost the same as VLA, and if you find difference you can write a beter wrapper or a few adapter functions. The place of memory allocation is not something you can discover legally in the program anyway. In case you'd hit some performance bottleneck, that is doubtful from such a change, you can rearrange a small portion of code.

于 2013-06-18T00:51:51.387 回答
0

如何使用 std::vector 替换数组?

于 2013-06-17T23:35:07.870 回答