I have a contrived example. I think the key point is that there is an illegal conversion into a base class. I should not be able to have an array of MyBase.
This example compiles on my computer in VS2013:
#include <vector>
#include <iostream>
struct MyBase {
virtual size_t Count() = 0;
};
struct MyContainer : MyBase {
size_t Count() override;
};
size_t MyContainer::Count() {
return 4;
}
int main() {
MyContainer countable;
MyBase x[] = { countable };
std::cout << x[0].Count() << std::endl;
return 0;
}
Is this getting the same error on other compilers?
Why am I getting a linker error instead of a compiler warning? (I do get an Intellisense warning)
Note
The question is not what is happening here or how to fix it. I know that. I was wondering why it is a linker error instead of a compiler error and whether that is specific to my compiler only.
To make it clear, I know that this is a "fix":
int main() {
MyContainer countable;
MyBase * x[] = { &countable };
std::cout << x[0]->Count() << std::endl;
return 0;
}
But fixing is not the issue here. What I do not understand is why the error is not diagnosed by the compiler but instead by the linker.