Solved

VC++ seems to not compile when needed

Posted on 2003-11-30
17
241 Views
Last Modified: 2010-04-01
Hi,

I have a class implemented in a.cpp and a.h . (Class CA inherits from some other class)
I then add a virtual function declaration, f(), to CA in a.h, but add the implementation to another .cpp file, not a.cpp.
I press F7, and when running the instance of f() in the superclass is involved.

I have to actually modify a.cpp in order that the build actually compile the change and the f() in CA will be called.
In short, it seems like the default rules about what has to recompile are buggy.

Note: I use precompiled headers , but not for the specific a.h in question.

Is this a known bug? Is there a workaround in some compilation swithches? (i.e. I don't want to rebuild all or to remember to manually change a.cpp).
0
Comment
Question by:mco
  • 9
  • 8
17 Comments
 
LVL 19

Expert Comment

by:mrwad99
ID: 9849953
You may want to download service pack 5 (SP5) for VC++, which you can get from the Microsoft site.

I dont know for sure if what you desribe is a documented problem, but I dont have this issue as far as I know and I have SP5 installed.

Hope this helps :)
0
 
LVL 1

Author Comment

by:mco
ID: 9851092
I forgot to mention, I use VC++ version 6. Does what you mention still hold?
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 9851143
Yes I think so.  

If you have Visual Studio .NET then it does *not* hold, but if you just have Visual Studio then you need SP5 if it is not previously installed.  

Also what version of VC++ are you running ?  Professional ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:mco
ID: 9851763
Enterprise
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 9852160
Well, either way try the service pack and come back :)
0
 
LVL 1

Author Comment

by:mco
ID: 9905650
Tried the SP and it didn't help.
Later I also found that I already had SP5 beforehand - it just doesn't say it in the about box.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 9906365
Sorry to hear that.  I am out of ideas.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 9906445
Could you post the code you are using so I can have a fiddle on my machine please ?
0
 
LVL 1

Author Comment

by:mco
ID: 9906683
My project is gigantic but I will try to create a sample project that reproduces the problem.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 9906687
Nice one.  Hopefully the problem can be nailed then !
0
 
LVL 1

Author Comment

by:mco
ID: 9910984
Since I don't see how I attach files here, please send me your email address to uiodocrawfd5@jetable.com and I will email you the sample
0
 
LVL 1

Author Comment

by:mco
ID: 9911045
Will send soon.
I just checked it on Visual C 7 (.NET), and there the problem
does not occur anymore.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 9911055
Hmm.  Interesting.  Looks like a problem with VC++ then !  Never heard of it before though, so it looks like you have your answer.  It would be interesting to still see your code though.
0
 
LVL 1

Author Comment

by:mco
ID: 9911097
I still have a problem, though, because for real work I cannot switch to .NET (for unrelated reasons).
I am hoping to find some secret compilation switch or something.
0
 
LVL 19

Accepted Solution

by:
mrwad99 earned 150 total points
ID: 9919397
Right I have had a good look at your code and experience exactly the same problem as you do.

>>This problem does not occur often, because by convention, a classe's methods are implemented
in the .cpp file of the class. In the example above this convention was not used.

Yeah that is the answer.  I am still a little confused as to why you chose to implement CDerived::f() from withinBuildProblemDlg.cpp, and not from within Derived.cpp; it would be interesting to hear your reasons.  All I can suggest is to create a pointer question to this question in both the C++ (again) and the MFC areas, possibly even the Windows Programming area too.  I am sure that someone out there must know, or at least have the resources to find out.

0
 
LVL 19

Expert Comment

by:mrwad99
ID: 9919437
Hmm; interested at the fact that you decided to accept this as an answer, but ta anyway.  Personally I would have left it open.

Anyway best of luck in the future with your coding. :)
0
 
LVL 1

Author Comment

by:mco
ID: 9919457
Hi, I accepted the answer in order to close this. From experience, after a number of days people don't see it and it just stays until I get some automatic email from EE. Thank you for your help.

The reason the function was not implemented in its conventional place has to do with the way our code is organized. Our codebase compiles in several configurations, with GUI to create a desktop application, and without GUI as a DLL that links to some COM interface.
The function in question (corresponding to f() in the sample), is GUI related. The .cpp file is general.
One solution would be to add #ifdefs for conditional compilation, but it was decided here it was better to put f() in the file dealing with GUI stuff.
In any case, we do not want to organize our code in other ways only because of bugs in VC++.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question