views:

201

answers:

3

Is there a "call stack" for compiler errors in Visual Studio 2005 (C++)?

For example, I am using a boost::scoped_ptr as the value in a QHash. This is however causing the following compile error:

1>c:\qt\include\qtcore\../../src/corelib/tools/qhash.h(743) : error C2248: 'boost::scoped_ptr<T>::operator =' : cannot access private member declared in class 'boost::scoped_ptr<T>'

From the build output I know which of my source files is causing the error and the line number in the qhash.h that is causing the error but I am trying to track down the line number in my source file that is generating the error (hence the "call stack" idea).

Please note, I am not looking for the solution to the problem of using a scoped_ptr in a QHash but the problem of tracking down where compile errors are generated. This would also be useful for helping track down weird warnings. More often than not I run into this problem when using templated classes.

Thanks!

A: 

If you look at the build output, you should see which project and which .cpp file was being compiled when this error occurred.

There is really no notion of "call stack" here, because the compiler processes one source file at a time. You have a compiler error in the header file, so you need to find out which source file including that header was being compiled.

Dima
I didn't mod you down, but I did update my question to be a little more specific as to what I was looking for.
Jesse
-1: The fact that a single compilation unit is considered at a time does not prevent the compiler from knowing where the incriminated call comes from. This kind of errors is often caused by something at a higher level than the line reported by the compiler.
RaphaelSP
In that case, the line in your source file causing this error would be the one which declares an instance of QHash using the scoped_ptr. This is the thing with templates. scoped_ptr must be violating an assumption that QHash makes about its template parameter.
Dima
A: 

These types of errors can be hard to track down. Usually I end up comment out code and finding the offending line and working from there. After doing it a while you will learn to better read the error messages and understand what tripped up the compiler. As it stands the compilers error messages are just horrible.

In this case it is saying that you have an object of type boost::scoped_ptr<T> that it is trying to copy but the class won't let you (operator= and the copy ctor are both hidden). So you need to look at how the class is used and see why it is trying to copy it. Maybe a scoped_ptr isn't what you need. Maybe you need a shared_ptr?

Matt Price
+1  A: 

Sometimes with strange errors it helps to preprocess the file and look at that output. With VS look for "Generate Preprocessed File" under preprocessor settings (or set the /P switch). This will generate XXX.i from XXX.cpp which may help you figure out the problem.

Make sure you turn off the switch after, with this option turned on it won't generate an obj file.

Dolphin
I just had a chance to check this. I know which line is causing the problem but the /P switch did not help in figuring it out. Good idea though.
Jesse