Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Failed compile when not using explict constructors

Options
LegacyForum
LegacyForum Posts: 1,664 ✭✭
(Entered for David Mann)

I made a class to add to the Common vcProj called AdjacentChannels. The defined constructor passes in a parameter. The default constructor AdjacentChannels() is not defined in the file. When I call the GenerateStubs I will get the following error:
Precompiling source: UAV\MAIN\Source Files\TestExecThread.cpp ...
...result is up-to-date.
Precompiling source: UAV\MAIN\Source Files\ThreadBase.cpp ...
cl.exe /Zi /Od /IC:\MYDATA\UAV\OFP\APPL\Common\inc /IC:\MYDATA\UAV\OFP\MAIN\inc /Gm /EHsc /RTC1 /MTd /DWIN32 /D_LIB /D_MBCS /nologo /ZI /Gd -DPARASOFT_CPPTEST "-Ic:\\program files\\parasoft\\c++test7.0vs2003extension\\plugins\\com.parasoft.xtest.libs.vstudio.cpp\\os\\win32\\x86\\etc/include" -I "c:\\program files\\parasoft\\c++test7.0vs2003extension\\plugins\\com.parasoft.xtest.libs.vstudio.cpp\\os\\win32\\x86\\etc\\include" -DCPPTEST_TIMEOUT_PER_TEST_CASE= -D_insure_version_=_insure_version -DCPPTEST_SUPPLEMENT_USED -w -nologo -c -Tp c:\\Mydata\\Uav\\Ofp\\Main\\src\\ThreadBase.cpp -Fo"C:\\MYDATA\\UAV\\Build\\Visual C++\\.cpptest\\MAIN\\file-data\\ThreadBase.cppc309bee9\\ThreadBase.cpp.obj"
ThreadBase.cpp
c:\MYDATA\UAV\OFP\MAIN\src\ThreadBase.cpp(6) : error C2512: 'AdjacentChannels' : no appropriate default constructor available
Process exited with code: 2 (error).
...failed.
"Generate Stubs" (Execution) for UAV\MAIN finished with error(s). Examine the log above for details.
But I do not want a default constructor. But to try to get past this error I make a default constructor and place it into the private section of the code since I do not want anybody to use it. I then get the following error:
Precompiling source: UAV\MAIN\Source Files\ThreadBase.cpp ...
cl.exe /Zi /Od /IC:\MYDATA\UAV\OFP\APPL\Common\inc /IC:\MYDATA\UAV\OFP\MAIN\inc /Gm /EHsc /RTC1 /MTd /DWIN32 /D_LIB /D_MBCS /nologo /ZI /Gd -DPARASOFT_CPPTEST "-Ic:\\program files\\parasoft\\c++test7.0vs2003extension\\plugins\\com.parasoft.xtest.libs.vstudio.cpp\\os\\win32\\x86\\etc/include" -I "c:\\program files\\parasoft\\c++test7.0vs2003extension\\plugins\\com.parasoft.xtest.libs.vstudio.cpp\\os\\win32\\x86\\etc\\include" -DCPPTEST_TIMEOUT_PER_TEST_CASE= -D_insure_version_=_insure_version -DCPPTEST_SUPPLEMENT_USED -w -nologo -c -Tp c:\\Mydata\\Uav\\Ofp\\Main\\src\\ThreadBase.cpp -Fo"C:\\MYDATA\\UAV\\Build\\Visual C++\\.cpptest\\MAIN\\file-data\\ThreadBase.cppc309bee9\\ThreadBase.cpp.obj"
ThreadBase.cpp
c:\MYDATA\UAV\OFP\MAIN\src\ThreadBase.cpp(6) : error C2248: 'AdjacentChannels::AdjacentChannels' : cannot access private member declared in class 'AdjacentChannels'
c:\MYDATA\UAV\OFP\APPL\Common\inc\AdjacentChannels.h(19) : see declaration of 'AdjacentChannels::AdjacentChannels'
c:\MYDATA\UAV\OFP\APPL\Common\inc\AdjacentChannels.h(6) : see declaration of 'AdjacentChannels'
Process exited with code: 2 (error).
...failed.
"Generate Stubs" (Execution) for UAV\MAIN finished with error(s). Examine the log above for details.
The code provided is with AdjacentChannels with the default constructor in the private section. Just comment out the default constructor to see the first error described in this section. If the answer is to just incldue private functions as part of the test configuration, then my followup would be what if I just wanted to test the public functions? The AdjacentChannels is referenced in ThreadBase.h as an attribute