Quick Search

Back to main page



Undefined Reference to WinMain

Type: Build error message

Your program can't find main(), the main entrypoint to the program.

  1. Make sure you've written your int main() function.
  2. Make sure you're working within a project, and didn't just open the files separately.
    Look at your solution explorer / project explorer - does it list a project and your code files, or is it empty?

Undefined reference to ___

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?

ABC already defined in XYZ

Type: Build error message

This error is saying that a function has already been defined elsewhere. There could be a few reasons:

  • Maybe you're missing the #ifndef file guards in a .h file.
  • Maybe you've re-defined the same function in multiple files or locations.
  • Maybe you need to run a clean + rebuild because old obj files are causing issues.
  • Maybe you have an #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!

Memory access violation

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.

  • Enable long paths
    The Windows documentation(Windows documentation: Maximum Path Length Limitation) has some information on enabling long paths.
  • Move your project directory
    If you move your project directory to something like 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

  • Try to close Visual Studio and re-open it.
    Sometimes if your program crashed last time you ran it, Visual Studio will be unable to update the .exe file and give this error.
  • Turn off your virus scan
    Sometimes your virus scan will see the .exe file you just built as an ``unknown threat'' and prevent it from opening, which also causes this error.

Code::Blocks: error: ld returned 1 exit status

Type: CodeBlocks message

  • Make sure you do not have any #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.

XCode: Cannot find functions

Type: Xcode error

This is a result of creating a new file in XCode, but choosing the wrong file type. When adding .cpp files, make sure you select a C++ file object.

XCode: Where are my output/input text files??

Type: Xcode error

You will need to set up a Working Path for your projects in XCode. You can get to this option by going to the menu bar: Scheme -> Edit Scheme

You will want to set your working directory to a specific path where you can locate the text files.

Git: There is no tracking information for the current branch.

Type: Git error

There is no tracking information for the current branch. Please specify which branch you want to merge with.

Try to fix this by running

git pull origin main

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: fatal: not a git repository (or any of the parent directories): .git

Type: Git error

fatal: not a git repository (or any of the parent directories): .git

You are not running your git commands from within a repository folder. Make sure you open Git Bash within a folder, or use cd commands to navigate to your repository path.

Git: error: Browse.VC.opendb Permission denied

Type: Git error

error: open("..../Browse.VC.opendb"): Permission denied
error: unable to index file '.../Browse.VC.opendb'
fatal: adding files failed

This happens because Visual Studio is still open. Close Visual Studio before running git add .

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" );

Access item at position ___

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();

Create a basic program loop

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

TEMPLATE

Type: Common instruction

TEMPLATE

Type: Error

TEMPLATE

Type: Course policy