We usually define classes that are often used like this:
class SomeClass
{
// Some code here
};
typedef std::shared_ptr<SomeClass> SomeClassPtr;
Because frankly having to type std::shared_ptr<SomeClass> every time is a suicide.
However Visual Assist, addon that my company paid for on top of Visual Studio, cannot cope with either SomeClassPtr or std::shared_ptr<SomeClass> and give member suggestions. Strangely though, I noticed that it handles QPointer<SomeClass> without any problems and gives SomeClass member suggestions as expected.
I noticed that status bar shows these two messages after I type pointer-> (right after typing > character):
IntelliSense: 'No additional information available' (See 'Troubleshooting IntelliSense in C++ projects' for further help.)
Which is weird because IntelliSense (I prefer to call it DumbSense) is turned off. Second message that appears only for 200ms:
VA X: Parsing D:\ ... \myFile.cpp
myFile.cpp here refers to the file being currently edited.
Can I do anything at all to teach Visual Assist to properly give suggestions on std::shared_ptr smart pointers?
Related
I've currently set up a environment for learning Microsoft Dynamics 365.
While I am playing around with code, I am getting a million warnings about missing documentation.
As:
I am a strong believer in "Clean Code"; and
I especially don't want to document all these things while just messing about to learn; and
I want visibility of other warnings which may be more important or at least interesting; and
I prefer explicit code.
I want to suppress all the warnings and always include the "public" keyword by default for all my classes.
So, I want to change the template from:
class AssetConsistencyCheck
{
}
to
[SuppressBPWarning("BPXmlDocNoDocumentationComments", "Prefer clean code!")]
public class AssetConsistencyCheck
{
}
Is this possible, and if so how?
I have been writing Java for a long time using Eclipse, now trying to switch to C++ in Visual Studio. From Eclipse/Java I know such auto-complete features: I write
bar = Foo.valueOf(x);
bar.doSomething(y, z);
and Eclipse offers me both to import whatever Foo I might mean, and declare bar as local variable, field, or parameter. Or create the function doSomething() with the appropriate signature, auto-adding missing imports to Foo. I am missing a corresponding feature on Visual Studio 2015, which does for example
add the corresponding #include and #pragma comment(lib, statements,
add these statements in a clear order, so that they work as expected (something like organize imports),
add namespace statements
declare variables, fields, and parameters on click/keypress
create function bodies, adding the corresponding foreward declarations to the respective header files, adding missing includes required by the declaration
…
The only things that I found so far is the “add class” dialog. When writing an unknown function name, right clicking and choosing “quick actions and refactorings” → Create declaration / definition, a window opens with the text
int main(int argc, char * argv[]);
but it does not create a definition for that function.
Are there some better “save me typing work” functions available in Visual Studio 15, and if yes, how can I benefit from them? Is there another way I could go, such as writing the C++ program (Windows API) in an other IDE (are there any for Winapi C++ which do better?)
Resharper by JetBrains does what you are asking for more or less. It will notice an error in your code, whether it being that something wasn't fully initialized, or something that you needed to include, or a host of other things.
It is not free though, but you can try it on a 30 day trial.
I don't know of an IDE that supports winapi functions like you're asking though. I think you'll just have to pick your favorite IDE and get used to it.
I'm seeing something weird happening with Visual Studio 2015 Community. Code that worked perfectly in VS2012 crashes at startup when ported to VS2015, before main is invoked: the classic symptoms of some static initialization mess. I have a few static variables, but used properly, with the standard "Construct On First Use" pattern, e.g.:
const int& i()
{
static int *v = new int(1);
return *v;
}
The code above causes an assert from the runtime while initializing the program (see image http://i.stack.imgur.com/nsQGS.png). Pressing retry simply quits the program: no call stack, no information whatsoever.
The code below however works flawlessly:
const int& i()
{
static int *v = nullptr;
if (v == nullptr)
v = new int(1);
return *v;
}
It seems to me that VS2015 is doing what looks like some (illegal) optimization (even in a debug build), by executing the static variable initialization code during program initialization, and not the first time that the function is called, as the C++ standard requires.
I tried several variations of the code above: class methods, free functions, different objects (std::vector, cv::Mat), always with the same result: the static pointer has to be initialized to null or the program doesn't start.
So... am I missing something or is VS2015 actually messing up badly?
UPDATE:
I spent some time trying to find the minimal setup that shows the problem, and this is what I got:
create a project using the "CLR empty project" template.
add a cpp file, containing just the offending function and main(). Main can be empty, it doesn't matter: the bug occurs BEFORE it is even reached.
add 'main' as entry point (or you get a link error).
The x86 version works, but the x64 doesn't.
For comparison, a project with the identical code but created as "Win32 console application" doesn't have the problem, even after adding the /CLR option. I can see differences in the vcxproj files, but none justifies the error, although one or more of them clearly IS the cause.
Is there a way to upload a zip with the project?
Well, #bogdan got it right. My project had a mix of settings that was neither /SUBSYSTEM:CONSOLE nor /SUBSYSTEM:WINDOWS. Once I fixed that, everything started to work as expected. My test projects had the same problem, I blame Microsoft for not having a clear "CLR windows app" C++ template any more in VS2015 (they want to push you to use C# for that, which makes sense most of the times, but not always).
I found this page particularly useful in explaining all the different settings that have to be consistent (it's not just /SUBSYSTEM...).
I wish I could mark #bogdan's comment as answer, but I can't see anything to do that.
Thanks Bogdan!
Greetings,
First off, I am not a C++ developer, so please forgive my shortcomings....
I am attempting to take another developer's C++ unmanaged code and re-work it so it can be called from a managed DLL from our c#.net application. Please keep in mind that I'm a .net developer, and I haven't touched C++ in like 12 years. And when I did... I made a rock-paper-scissor game. :(
Anyway... I found a nice little note from another developer on a forum that suggested we go ahead and add a garbage collector to the class in the .h file with "Public __gc". Well, there are two classes I'm trying to convert to managed code, so I went ahead and did that... and one of them just instantly worked! The other... well, is throwing this error:
'cannot convert parameter 5 from 'char *__gc *' to 'char **'
Ok, so I know this has something to do with pointers pointing to more pointers and stuff... but here are the variables in question that DID work when the garbage collector wasn't added to the class name, and now won't build with it added:
<<< HEADER FILE >>>
public __gc class bob
{
...
public:
char *img_buff;
...
int init(void);
}
<<< CPP FILE >>>
int init(void)
{
...
nRet = is_AllocImageMem(hcam,
img_wid,
img_hgt,
depth,
&img_buff, << doesn't like it here
&mem_id );
...
}
Any suggestions or ideas? I just don't know enough about "*" and & and pointers and stuff in C++.
Thanks in advance. Best wishes!!!
What version of Visual Studio do you have? The __gc stuff is Managed C++, which was awful. You want C++/CLI, where the magic words are public ref class. Still, no matter which way you do this, you're going to have to understand pointers a little bit, because you're going to have code that says "I take a native pointer" and you intend to hand it a managed reference to something on the garbage collected heap. You'll have to change that code to make it work.
I am pretty sure using PInvoke is going to be a better plan for you because it won't require as much tweaking of the C++ code. If you have C++ expertise on the team my answer would be different.
We will convert a number of programs written in C++ and MFC in Visual Studio.NET 2002 to Visual Studio 2010. What problems can we expect to encounter? What changes are there in the libraries that are worth knowing?
MFC has had a number of breaking changes over those releases. All the changes are documented on MSDN, and usually they're pretty straightforward - function signature changes and the like (which can often be fixed simply by inspecting the compiler error message and working out what it wants instead).
I've been through this moving a project to VS 2008 and the two big ones were the "secure CRT" functions and the for loop scope change. (I can't remember precisely when that happened, but it might affect you.) Basically the compiler is your friend ... build the whole thing and it will find the problems, which you can then fix. You can suppress the secure CRT warnings but you might as well get them taken care of.
I'm not aware of any "I'm happy to compile but I won't do quite what I used to do at runtime, thus ruining your world" breaking changes in MFC or C++ over the last decade. So once you make the compiler happy you should be confident your app still works.
dynamic_cast will behave differently at runtime
class A
{
}
class B : public A
{
}
class C : public A
{
}
//...
C* c = new C();
//This used to work, i.e. didn't return NULL, with 2002
B* b = dynamic_cast<B*>(c); //... won't work any more --> returns NULL.