Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:10:21+00:00 2026-06-14T14:10:21+00:00

When I attempt to compile the following code, I get this error: obj\Debug\main.o||In function

  • 0

When I attempt to compile the following code, I get this error:

obj\Debug\main.o||In function `main':|
C:\Users\dmarr\Documents\CSharper\Dallas\CPlusPlus\WHYGODWHYCB\main.cpp|16|undefined reference to `bag::bag()'|
||=== Build finished: 1 errors, 0 warnings ===|

At first, I had bag.h and bag.cpp as two separate files- many of the answers relating to “Undefined Reference” here suggested to move the contents of the .cpp file into the .h file- so I did. However, I am still getting the aforementioned error when compiling.

aItem.cpp:

//aItem .cpp implementation file
#include "aItem.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;

//setting this up default
aItem::aItem()
{
    m_itemName = "Default Name";
    m_itemType = "Default Type";
    m_damage     = 9001;
}





void aItem::setName(string name)
{
    m_itemName = name;
}

void aItem::setType(string type)
{
    m_itemType = type;
}

void aItem::setDamage(int damage)
{
    m_damage = damage;
}

string aItem::getName()
{
    return m_itemName;
}

string aItem::getType()
{
    return m_itemType;
}

int aItem::getDamage()
{
    return m_damage;
}

aItem.h:

#ifndef AITEM_H_INCLUDED
#define AITEM_H_INCLUDED

#include <iostream>
#include <string>
#include <vector>
using namespace std;


class aItem
{
public:
    //constructor
    aItem();


    //Methods
    void ItemCreate(string itemName, string itemType, int damage);
    void setName(string name);
    void setType(string type);
    void setDamage(int damage);
    string getName();
    string getType();
    int getDamage();

private:

    string  m_itemName;
    string  m_itemType;
    int m_damage;


};

#endif // AITEM_H_INCLUDED

bag.h:

#ifndef BAG_H_INCLUDED
#define BAG_H_INCLUDED

#include "aItem.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class aItem;

class bag : public aItem
{
public:
    //constructor
    bag();

    //methods
    //void delItem(aItem aitem);

void addItem(aItem var)
    {
        m_items.push_back(var);
    }

void bagList()
    {
        for( vector<aItem>::size_type index = 0; index < m_items.size(); index++ )
            {
                //Makes a numerical list.
                cout << "Item " << index + 1 << ": " <<  m_items[index].m_itemName << endl;
                index+= 1;
            }
    }
private:
     vector<aItem> m_items;
};

#endif // BAG_H_INCLUDED

…and finally, main.cpp:

// WHYGODWHY.cpp : Defines the entry point for the console application.
//

#include "aItem.h"
#include "bag.h"
#include <iostream>
using namespace std;

int main()
{
    aItem woodSword;
    woodSword.setName("Wooden Sword");
    woodSword.setDamage(3);
    woodSword.setType("WPN");

    bag inventory;
    inventory.addItem(woodSword);
    inventory.bagList();


    cout << "Name: " << woodSword.getName() << endl;
    cout << "Type: " << woodSword.getType() << endl;
    cout << "Damage: " << woodSword.getDamage() << endl;
    //cout << "Inv: " <<
    int pause = 0;
    cout << "Pause!";
    cin >> pause;

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:10:23+00:00Added an answer on June 14, 2026 at 2:10 pm
    //constructor
    bag();
    

    You are missing a definition of your constructor. The compiler will only auto-generate it if you don’t declare it. As soon as you do, it is your responsibility to provide an implementation.

    Note: If you do, you can of course go back to separating .h and .cpp as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I compile my Android Application with Proguard enabled I get the following error:
When I attempt to compile the output of this trivial lex program: # lex.l
I get a compile error, Cannot implicitly conver type 'System.Collections.ObjectModel.ObservableCollection to ProddataRecsObservable'. An explicit
I don't understand this cryptic error message but I get 30 of `'value_type' :
I found only one attempt to create such compiler - http://sourceforge.net/projects/xsltc/ . But this
First attempt to use this cool site - after searching for 2 hours: So
The following is my attempt at a prepare statement. It is causing the page
This is my first attempt at responsive design, so I'm keeping it simple. I
I have the following code that is to be propperly converted to cython: from
I am getting the following error message when compiling or attempting to run my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.