Undefined Reference to WinMain
Type: Build error message
Your program can't find main(), the main entrypoint to the program.
int main()
function.Type: Build error message
A variable or function either has not been declared
or cannot be found at the current location in the program.
Check to make sure you don't have any typos, that your variables have been declared,
that your #include
are set up properly,
and that any functions declared also are defined
elseware.
Use of undeclared identifier XYZ
Type: Build error message
You're trying to use a variable XYZ
but you have not declared it at this point in the program.
Look for your variable declaration and make sure it shows up before any code that uses this variable.
Unresolved external symbol ABC
Type: Build error message
This usually means you've made a call to a function that doesn't exist - perhaps you've declared it somewhere, but never wrote the function's definition.
Object of abstract class type is not allowed / Cannot instantiate abstract class
Type: Build error message
You're trying to create an object (that is, a variable whose data type is a class), and the class you're using is still an abstract class. This could be because you haven't overridden all of its parents' pure virtual functions, or perhaps a typo between the parent class' function signature and the child class' function signature.
Example:
class IQuestion
{
// ...
virtual bool AskQuestion() = 0; // pure virtual function
};
class MultipleChoiceQuestion : public IQuestion
{
// ...
virtual bool AskQuestion() const; // this one is marked as CONST; not the same signature
// Class assumes "virtual bool AskQuestion()" is a different inherited function.
};
cannot convert from ABC to XYZ
Type: Build error message
The program is expecting an XYZ
data type in a location where you're giving it an ABC
type instead.
If you're working with a class object, perhaps you need to pass a member variable of that class object instead?
Type: Build error message
This error is saying that a function has already been defined elsewhere. There could be a few reasons:
#ifndef
file guards in a .h file.#include
for a .cpp file. You should never include a .cpp file.Operator -> applied to ABC instead of pointer type
Type: Build error message
You're trying to dereference an object that is not a pointer. Perhaps you're storing a vector of pointers? Make sure you're accessing a single element.
error: implicit instantiation of undefined template 'std::basic_ifstream
Type: Build error message
Don't forget to put
#include <fstream>
in the code when you're using ifstream
or ofstream
in your program!
Type: Runtime error message
If the memory address it shows you is 0x00000
or something
with a lot of zeroes, then you're trying to access a pointer that is pointing
to nullptr.
Another problem might be going outside of bounds of an array.
Windows maximum path length error
Type: Windows error
Windows has a setting that limits the maximum file path length. If your repository is deep down many folders, you may encounter this issue.
C:\
instead of
the desktop (which is actually C:\Users\blahblahblah\Desktop
)
or the default visual studio project path (C:\Users\blahblahblah\source\repos
)
this will help avoid this maximum path length issue.
Visual Studio: Fatal error LNK1104: cannot open file ...exe
Type: Visual Studio error
Code::Blocks: error: ld returned 1 exit status
Type: CodeBlocks message
#include
statements that include a .cpp file. Includes only work with .h and .hpp files, or library files in < > brackets.Code::Blocks: Modern C++ features not working
Type: CodeBlocks error
In this case you'll need to set up your compiler to build for a modern C++ version, rather than
the default of C++98 (from 1998).
In Code::Blocks, go to Settings > Compiler...
Then, check the box that is next to the Have g+ follow the C++17 ISO C++ language standard [-std=c++17] option,
or the C++14 one if that's not available.
Type: Xcode error
XCode: Where are my output/input text files??
Type: Xcode error
Git: There is no tracking information for the current branch.
Type: Git error
Git: [rejected] error: failed to push some refs
Type: Git error
! [rejected]
error: failed to push some refs
hint: Updates were rejected because the tip fo your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
The hint gives you the solution: Run git pull
and then repeat your git push
.
Git: error: Browse.VC.opendb Permission denied
Type: Git error
Increment or Decrement variable by
Type: Common instruction
Increment: Add to the VARIABLE.
var++;
var += 2;
Decrement: Subtract from the VARIABLE.
var--;
var -= 2;
Declare a variable of type ABC and assign it a value of XYZ.
Type: Common instruction
Declare a variable. A variable declaration takes the form:
DATATYPE VARIABLENAME;
Also, assign a value to that variable. Use the assignment operator =
.
Declare an input (or output) file stream and open the file ABC.txt.
Type: Common instruction
The input file stream data type is ifstream
. The output file stream data type is ofstream
.
Both of these data types require the inclusion of the fstream
library: #include <fstream>
Use this as a data type to declare a variable.
Once you have a variable (e.g., infile
), you can open a text file like this:
infile.open( "ABC.txt" );
Type: Common instruction
Access an element of the array at the position given.
// Access element of m_arr at position m_count:
m_arr[m_count] = "Bob";
// Access element of m_students at position m_studentCount and call Display():
m_students[m_studentCount].Display();
Type: Common instruction
Create a loop (usually in main()
) that continues looping until the user decides to quit.
bool done = false;
while ( !done )
{
cout << "0. QUIT" << endl;
cout << "1. SOMETHING" << endl;
cout << "2. SOMETHING" << endl;
cout << "3. SOMETHING" << endl;
int choice;
cin >> choice;
if ( choice == 0 )
{
done = true;
}
// etc.
}
Iterate through elements of ARRAY
Type: Common instruction
Use a for loop to iterate over elements of the array, usually starting at 0 and ending at size-1.
string arr[10];
for ( int i = 0; i < 10; i++ )
{
arr[i] = "";
}
Set the private member variable to the value of the parameter passed in (Class SETTER function)
Type: Common instruction
You're writing a Setter function for a class that has a private member variable. Whatever parameter is passed into this Set function, you're using that as the new value of that private member variable.
Class declaration:
class Example
{
public:
void SetVar( string value );
private:
string m_var;
};
Setter function:
void Example::SetVar( string value )
{
m_var = value;
}
Return the value of the corresponding private member variable (Class GETTER function)
Type: Common instruction
You're writing a Getter function for a class that has a private member variable. Return the value of that private member variable.
Class declaration:
class Example
{
public:
string GetVar();
private:
string m_var;
};
Setter function:
string Example::GetVar()
{
return m_var;
}
Add a file guard to your header files
Type: Common instruction
Header files (.h and .hpp) need to have file guards to prevent duplicate imports.
In a header file:
#ifndef _FILE_NAME
#define _FILE_NAME
// Put your code here
#endif