Solved

VC++ seems to not compile when needed

Posted on 2003-11-30
17
233 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

757 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now