[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppCompileError
For compile errors when using the Boost C++ Library see Boost compile errors.
Solution: read the code carefully.
This code is perfectly fine... But I copied it from a Microsoft Word document. Therefore, it has RichText additions. This can be revealed using a plain-text editor (e.g. under LINUX use: 'more main.cpp'). In a plain-text editor this line looked like:
But
For example, the assert statement used by the Boost C++ Library use the SAME #include guard! This can cause your own assert statement to not be included.
caused by:
The compile error is solved by changing this to:
Congratulations, as you have just let boost find out a nasty run-time error for you [1], thanks to boost::checked_delete. It is caused by you forward declaring a class in a header file, without #including the class's header file in the implementation (.cpp) file. After #including it the error is gone.
See boost::checked_delete why you otherwise would have had a nasty run-time error.
This is caused by a combination of a #include guard and a function declaration without a terminating semicolon ;, e.g. in the code below:
Add the semicolon and everything will be fine.
The answer is to #include <string>, which contains the definition of the function lacking.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppCompileError
(C++) Compile error
An error given to you by your compiler. It prevents your program from running. Prefer compile-time errors over run-time errors (see reference 1). The naming of these depends on the compiler.For compile errors when using the Boost C++ Library see Boost compile errors.
Other errors
- C++ compile errors
- C++ linking errors
- C++ runtime errors
- C++ Builder compile errors
- C++ Builder linking errors
- C++ Builder run-time errors
- C++ Builder misc errors
List of compile-time errors
Overview
- syntax error
- stray '\342' in program
- [C++ Error] UnitMain.cpp(3): E2451 Undefined symbol 'cout']]
- [C++ Error] UnitMain.cpp(34): E2268 Call to undefined function 'Assert'
- [C++ Error] _algo.c(432): E2268 Call to undefined function 'rand'
- Nasty boost::shared_ptr nasty compile error
- [C++ Error] E2092 Storage class 'static' is not allowed here
- [C++ Error] E2138 Conflicting type modifiers
- [C++ Error] exception(78): E2141 Declaration syntax error
- [C++ Error] checked_delete.hpp(32): E2450 Undefined structure 'MyStructure'
- [C++ Error] _config.h(488): E2141 Declaration syntax error
- 'operator<<' not implemented in type 'ostream' for arguments of type 'std::string'
syntax error
A common newbie compile error. It means that the compiler could not parse a line of code. This means that you probably made a typo somewhere.
//Error program
const double x = (1.0/(2.0/(3.0/(4.0/5.0))); //Forgot a bracket
const double y = 5.0 + ; //Forgot to write somehing after the plus
for (unsigned int i=0; i<10; ++i)
{
std::cout << "Hello world" << std::endl;
//Forgot a closing accolade
const double z = 8.0 //Forgot semicolon
return 0;
}
Solution: read the code carefully.
Error: stray '\342' in program
I got this error in:int main() { std::ofstream myOut("test.txt"); //ERROR return 0; }
- include <fstream>
This code is perfectly fine... But I copied it from a Microsoft Word document. Therefore, it has RichText additions. This can be revealed using a plain-text editor (e.g. under LINUX use: 'more main.cpp'). In a plain-text editor this line looked like:
So, the RichText-ed apostroph " should be replaced with a 'plain' apostroph.int main() { std::ofstream myOut(<E2><80><gC>test.txt<E2><80><gD>); //ERROR return 0; }
- include <fstream>
[C++ Error] E2451 Undefined symbol 'cout'
This error occurs when the program does not know the command 'cout' (which is the reason why it thinks it is a 'symbol'(e.g. an integer). #include 'iostream.h' to solve this. See also the Hello World program.[C++ Error] UnitMain.cpp(34): E2268 Call to undefined function 'Assert'
You must be cautious when defining your own assert statement. Especially when als #defineing your own #include guards. Therefore, do the following: - Check if your own assert statement header file can be found in the right folder - Give your #include guard an original name. Do not://NO!!!//Your assert
- ifndef assertH
- define assertH
- endif
But
//Your assert
- ifndef BilderbikkelAssertH
- define BilderbikkelAssertH
- endif
For example, the assert statement used by the Boost C++ Library use the SAME #include guard! This can cause your own assert statement to not be included.
[C++ Error] _algo.c(432): E2268 Call to undefined function 'rand'
The compiler takes you to the header _algo.h, to the blue line below:
template <class _Distance>
inline _Distance __random_number(_Distance __n) {
- ifdef _STLP_NO_DRAND48
return rand() % __n;
- else
return lrand48() % __n;
- endif
}
It cannot find rand when you are not using namespace std. I solved it by changing the blue line to
return std::rand() % __n;
Nasty compile error with boost::shared_ptr
[C++ Error] shared_ptr.hpp(124): E2034 Cannot convert 'Y *' to 'BirdBase *' [C++ Error] shared_count.hpp(82): E2450 Undefined structure 'sp_counted_impl_p<Y>' [C++ Error] shared_count.hpp(82): E2315 'sp_counted_impl_p<Y>()' is not a member of 'sp_counted_impl_p<Y>', because the type is not yet defined [C++ Error] shared_count.hpp(82): E2034 Cannot convert 'sp_counted_impl_p<Y> *' to 'sp_counted_base *' [C++ Error] checked_delete.hpp(32): E2034 Cannot convert 'Y' to 'bool'
caused by:
//Removes the boost::shared_ptr<BirdBase> mMale from the class Couple
boost::shared_ptr<BirdBase> Couple::getMale()
{
boost::shared_ptr<BirdBase> male(mMale);
mMale.reset(0); //Set pointer to NULL
return male;
}
The compile error is solved by changing this to:
//Removes the boost::shared_ptr<BirdBase> mMale from the class Couple
boost::shared_ptr<BirdBase> Couple::getMale()
{
boost::shared_ptr<BirdBase> male(mMale);
mMale.reset(); //Remove the 0
return male;
}
[C++ Error] E2092 Storage class 'static' is not allowed here
When you make a class member variable static, then use the keyword static ONLY in the class declaration.
//Declaration
class MyClass
{
static double myDouble;
//Stuff
};
//Initialization
double MyClass::myDouble = 0.0;
//THIS ERROR: static double MyClass::myDouble = 0.0;
[C++ Error] E2138 Conflicting type modifiers
To quote the C++ Builder Help: 'This occurs when a declaration is given that includes more than one addressing modifier on a pointer or more than one language modifier for a function'. This can be due to, e.g.- you've made a class member function both static and const. Make it const if it does not modify the class its member variables.
[C++ Error] exception(78): E2141 Declaration syntax error
Takes you to the header exception to the line_STLP_BEGIN_NAMESPACEI do not know exactly what causes this, but I have observed the following: in my automatically created Unit, I had the following code:
//---------------------------------------------------------------------------After adding the semicolon, it worked again.//--------------------------------------------------------------------------- class Parameters { //Stuff }; void Dot(const Parameters& parameters) //Forgot semicolon!!!
- ifndef UnitParametersH
- define UnitParametersH
- endif
[C++ Error] checked_delete.hpp(32): E2450 Undefined structure 'MyStructure'
Your compiler will take you to this line:
template<class T> inline void checked_delete(T * x)
{
// intentionally complex - simplification causes regressions
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; //This line
(void) sizeof(type_must_be_complete);
delete x;
}
Congratulations, as you have just let boost find out a nasty run-time error for you [1], thanks to boost::checked_delete. It is caused by you forward declaring a class in a header file, without #including the class's header file in the implementation (.cpp) file. After #including it the error is gone.
See boost::checked_delete why you otherwise would have had a nasty run-time error.
[C++ Error] _config.h(488): E2141 Declaration syntax error
You are taken to the line below, in the header file exception_STLP_BEGIN_NAMESPACE
This is caused by a combination of a #include guard and a function declaration without a terminating semicolon ;, e.g. in the code below:
void sayHello() //FORGOT SEMICOLON[/b]
- ifndef UnitHelperH
- define UnitHelperH
- endif
Add the semicolon and everything will be fine.
'operator<<' not implemented in type 'ostream' for arguments of type 'std::string'
Caused by the following simple code:int main() { std::string s = "Hello"; std::cout << s; }
- include <iostream>
- include <vector>
The answer is to #include <string>, which contains the definition of the function lacking.
#include <string> int main() { std::string s = "Hello"; std::cout << s; }
- include <iostream>
- include <vector>
References
- 1) Herb Sutter and Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Chapter 14: 'Prefer compile- and link-time errors to run-time errors'.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
