I'm using VS Code for C++ with C/C++ extension (vscode-cpptools
) and finding that it doesn't give suggestions for certain things from templates inside templates that depend on the outer template's template parameter.
Here's an example:
template <typename T>
class B
{
public:
void do_st()
{
std::cout << "do_st" << std::endl;
};
};
template <typename T>
class A
{
public:
std::shared_ptr<B<T>> return_ptr()
{
return std::make_shared<B<T>>();
}
void do_ss()
{
return_ptr()->do_st();
// ^before I type "do_st()" here, "do_st" is not one of
// the suggestions, but I expected that it would be.
}
};
Why when I type
return_ptr()->
The intellisense didn't suggest do_st()
?
Is there any way to make that happen? Or does intellisense not support this?
Though in the scenario you showed, I think static analysis should be able to figure it out, it's not always that simple (C++ is a pretty gnarly beast of a language, and it just increases in complexity with newer language standards).
There are related (not-yet-resolved) issue tickes on the vscode-cpptools github page:
Autocomplete fails for templated class/struct #5039
A similar scenario to yours.
IntelliSense failing for smart pointers of template classes #9429
A very very similar scenario to yours and marked as a duplicate of:
Add UI to provide args for templates, to enable template IntelliSense #1946
This feature-request for is a mirror-feature of a feature that exists for Visual Studio where you can see intellisense and problems with a template when specific template arguments are provided. Quoting from one of the maintainers' comments in that issue ticket's discussion thread:
It turns out this is a "by design" limitation -- templates have errors turned off, because the type info is not known for the template args. We would have to add some UI that enables users to set the actual types of the template args.
You can increase the prioritization of those issue tickets by giving them a thumbs up reaction, and subscribe to them to get notified about any updates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With