inheritance in MS C++ using Visual Studio 2010 - c++

i have been going through the source code of an application which i downloaded from sourceforge.
i have a certain method which requires a pointer to an abstract class as a parameter.
class A;//abstract class
B::method(A *)
i cant create an object of A since its abstract.
so i can only pass pointer to object of child class of A in the B::method().
Now the problem is there are many classes in the source.
my problem is that how do i know which are the child classes of a parent class in visual studio 2010?
i have tried "find all references" for a virtual method of the abstract class (because its definition should be in the child class!) but without luck.
hope i could make my question clear!

Maybe "Solution Explorer" -> Your project -> Right Click Menu -> "Class Diagram" is what you're looking for ?
Another suggestion - try looking for " : public YourBaseClassName" strings and then "unwind" the inheritance. The usability certainly depends on the depth of your hierarchy. If there are multiple intermediate classes or multiple inheritance, then... Maybe, look at Eclipse+CDT ?

Related

How to automatically create virtual methods from inherited class in Qt Creator?

I am using QT4.8.4 + Qt Creator 2.8.1. Now I need to create several classes Child_X that inherit from another class Parent. In Parent I have several virtual methods.
Now I have to implement them in all of my Child_X classes. To save editing time, I'd like Qt do that for me automatically. When I remember right there is the possibility to have Qt create all the virtual methods. Does anybody know how?
Thank you
Sorry, I did not formulate correctly: I did not mean that Qt will automatically write the body of the methods. ( To invent that would probably make you very rich :-) )
I was talking about Qt writing all the headers of the virtual methods in the newly created (inherited) class. This saves a lot of writing/copying classnames etc.. The body would be empty in all the virtual methods.
Thank you
itelly
I hope you already found it, but maybe for others:
Right click on the class name in the editor.
In the menu, click on 'Refactor' and then on 'Insert virtual functions of base classes'.
You can choose to directly make the functions in the implementation file (as well as in the header file).
there is the possibility to have QT create all the virtual methods
There is no such possibility, because Qt can't read your mind and divine what those implementations are supposed to do.
Speaking of that - what are your virtual methods supposed to do? Please edit the question to fix that.

How to find derived classes in a solution in Visual Studio 2013?

In Visual Studio 2013 when I go to Class View, then search for a class, then expand "Derived Types" folder it shows me only the classes derived from this class in the current project, but not the whole solution. Is there a way to find all the derived classes in the solution in Visual Studio 2013 or perhaps some plugins? The language in focus is C++ (unmanaged).
I have the same question. So far I am making do with a regular expression that matches part of the declaration of the derived class:
:\s*(public|private|protected)?\s+ClassName
For example when searching for all classes derived from class A in the following:
class B : public A {};
The regular expression tries to match the : public A. Note this will not work when A is not first base class in the list of base classes. Also does not work for indirect descendants.

Why the class create by Qt creator has no destructor?

Every time I create a class, there is no destructor in the body of the class? Why is that? The Visual Studio will create a destructor automaticly but the Qt creator doesn't. Is there something special in the class of Qt?
In most well-designed C++ classes you don't need any custom code in the destructor and the default behavior is the right thing (i.e. destroying all members).
You can add a destructor if you want of course and please note that QtCreator mitigates the C++ annoyance of header/implementation duality by allowing automatic creation of the declaration from the implementation or vice versa (e.g. context menu -> refactor -> add public declaration).

Designing VS2012 project interaction: should I use an interface or a composite class across different projects?

I have the following design problem. For example I have 3 visual studio projects. They are called "TheGame", "OpenGLDevice" and "DirectXDevice". "OpenGLDevice" and "DirectXDevice" are also the name of a class inside the projects. As you may have guessed, TheGame handles the logic of the application and use one of the other two projects to draw things on the screen. My question is about how should TheGame interact with the two projects. Here are what I could think of.
Create a "DeviceContainer" base class, and a "OpenGLDeviceContainer" and "DirectXDeviceContainer" derived private inner classes in TheGame. The derived classes each contains a private member field of type OpenGLDevice or DirectXDevice. DeviceContainer would basically serve as wrappers.
Create a "IGraphicsDevice" interface in a fourth project and have all three projects reference it. Make OpenGLDevice and DirectXDevice both implement that interface.
I like approach 1 because I wouldn't need to create a fourth project and both OpenGLDevice and DirectXDevice would have no dependencies.
First of all, which of these two would be the best approach and is there a third solution which would be even better.
Second, if I do choose to use the interface approach, is there a better way than to declare the interface in a fourth project?

Enterprise Architect - Inherit methods from interface in class diagram

In Enterprise Architect ( Version 9.2.921 ) I want to make a class diagram. I have a class MyInterface which acts as an Interface . So in EA I choose stereotype <<interface>> and also marked it as abstract.
Now to keep it simple, my abstract interface defines one virtual function. Now I have a class MyChild , which is a child of my interface ( class MyChild :: MyInterface ) and which shall implement this function.
To do so in EA, I created a new class. Then right-click on it --> Advanced --> Parent .
As type I pick implementsand then I choose my Interface class.
On my class diagram the arrow from child to parent is correct ( dashed line, with empty arrow head in direction of the interface ).
Now the problem is, I would expect EA to add my abstract function from the interface right into the implementation class itself. So for example if I change/add/delete a virtual function in the Interface class it gets right away changed in the child classes. But the problem is, the function doesn't show up in the body of the child class.
Is there any way to do make Enterprise Architecht do this?
First off, there's another way of drawing connections which you may find easier. If you select the class in the diagram, you'll see a little arrow icon appear just above/right of the class. Click this, drag to the interface and drop, and EA will provide you with a set of possible connectors, with the most relevant ones first. This list is context-sensitive based on both the source and target element types (in this case, class and interface).
When it comes to the "Overrides & Implementations" dialog, there are some subtleties involved.
If a class realizes an interface, the class actually has the operations specified by the interface, although hidden, even if you don't select them to be implemented (which is why the interface operations are deselected by default in this dialog).
If you use the class in a sequence diagram, and make a call to it, you will see that you can select the interface-defined operation in the "Message Properties" dialog (provided "Show Inherited Methods" is selected). This name will be updated automatically if you rename the operation in the interface.
If you draw a generalization between two classes, you get the same behaviour in the sequence diagram. In addition, you can select display of a class' inherited (through generalization) operations by right-clicking it, selecting "Feature Visibility" and ticking "Show Operations." Note that this only works for operations arrived at through generalizations (from other classes), not realizations (from interfaces). I consider this a bug, but it may be by design.
If you do select an operation in the "Overrides & Implementations" dialog, that means you are making a copy of it. EA will not remember where the overridden operation came from, and won't update the name if you change it in the interface / abstract class.
Using the right-click - Advanced - Parent method bypasses the "Overrides & Implementations" dialog but creates the connector, as you've noted.
Now you mention that you create a class and then set the "interface" stereotype. This isn't the way to do it; you should instead create the interface using the interface symbol in the toolbox. A Class with the "interface" stereotype is not the same as an Interface and I'm not sure which of the behaviours I've described you'll get with that construct.
If it's an Interface you want, use that. If on the other hand you're talking about an abstract class, then Class is right and neither the abstract nor the concrete class should have the "interface" stereotype.
Note also that if you've got a code base you want to draw diagrams for, chances are that EA can reverse-engineer it for you (if it's in C++, C#, Java, or about a dozen other languages).
Okay I found a way:
Delete the connection between the two classes ( if there already was one )
Select Realization from the Class Relationships in the Toolbox
Draw a line from your Child class to the interface
When releasing the mouse you will be prompted to chose the function which your child shall implement
This way you don't have to retype all the function prototypes time and time again - but if you change the prototype in the interface, it won't change the according function in the implementations. ( Maybe there is another way too, but I don't know it yet... )
I had the same problem.
I'm not really happy with the answer. How to "Delete" the Realization
If "Delete"="Hide on Diagram", you will have two Realization-Assocs at the end
If "Delete"="Delete from Model" this Assoc be removed in other Diagrams, where it was used