Question

I am using VS2012 for a course project that we started from scratch, We are to use C++ to create something like this (I think the aggregation part is reversed):

https://www.dropbox.com/s/w2zh7yltbups6cm/class.png

Well , we had that on paper , wrote the code for each class with no problems, except we can't test because each class depends on another that was not finished at the time. Long story short : each class has its own untested code and VS does not detect any errors whatsoever and based on our previous experience we know that the code is correct, no syntax errors anyway.

When I start compiling some 500 errors come out of nowhere , some of them it says in "time.h" , I thought it was something wrong with the compiler , tried switching to C::B and see if it work but i needed a different compiler and I don't have the time to download any large files ,seriously , deadline in 2 days and internet speed sucks.

doing some research here (and googling around) I narrowed it down to cyclic dependencies and I learned that I can draw the diagram in VS and get code files , unfortunately it does it in C# while I have a C++ code (it has to be C++) .

How can I realize this diagram in C++ ? Which class should include which headers ? How can I avoid this in the future ?


EDIT: Solved it by removing all dependencies and disabling pre-compiled headers (Don't really know if I had to) , then I included each .h in its corresponding .cpp , then I included in each .h every header it needs to use. All that did not really solve my problem , it was the declarations !!! I did #ifndef myclass , #define myclass to each header and declared the used classes , I think it's what's called "Forward Declaration" (correct me if I'm wrong) Anyway it finally compiled and I will start testing .

If you have any remarks then by all means , you can add them.

Was it helpful?

Solution

Cyclic "dependency" can be. Why not? Because they are not dependencies, but associations with visible navigability. But you have some problems here.

  • Reservation should better have navigation to Member. Backward it could be, too. But Reservation should have Member instance as attribute. It is more simple way.

  • Also Rental is a class representation of association between DVD and Customer. And should have their instances as attributes. Again, back navigation IS possible, but do you need it? Maybe.

Another problem:

  • Title-DVD aggregation has correct direction, but it should be Composite, for there are no DVD without Title.

Testing: You can do unit tests, isolating classes from other ones by mocking first. After debugging that start to replace mocks with real classes. After that try unit tests without mocking, then normal auto tests, with automatic input/output/comparing.

As for code engineering, download VP UML enterprise "for testing version" and/or Enterprise Architect of Sparx, eval professional version. They both can do code engineering in C++.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top