0

I hope you will help me. So,I have this class and whenever I try to compile the main.cpp I get the errors: Undefined reference to 'Sally::Sally()', to 'void Sally::print()' and twice for 'Sally::~Sally()'

here is my header file:

#ifndef SALLY_H
#define SALLY_H


class Sally
{
    public:
        Sally();
        void print();
        virtual ~Sally();
    protected:
    private:
};

#endif // SALLY_H

here is my Sally.cpp file

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

Sally::Sally()
{

}
void Sally::print()
{
  cout<<"print something"<<endl;
}

Sally::~Sally()
{

}

here is my main.cpp file

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

int main()
{
    Sally salObj;
    salObj.print();

}

I saw a comment here that I should include the 3 files in a project but whenever I do I make a Console Application and it prints out "Hello world" even though I don't even have that anywhere. I'd love if someone can help me,I've been bugged with this for a couple of days and nothing seems to make it better.

2
  • What compiler are you using? you need to link Sally.cpp Commented Oct 6, 2013 at 11:58
  • Very hard to help with this from a distance. The problem is not the code, it's your understanding of Code::Blocks. Try and find someone who can sit down with you and show you what you are doing wrong. BTW you do need to create a project and add all your files to it, but obviously you are doing that wrong somehow. Commented Oct 6, 2013 at 11:59

1 Answer 1

3

Code::Blocks adds a default main.cpp file to a Console Application project. You need to remove that file, and add your own files by right clicking on the project name -> "Add files...". Make sure that you add all three files.

Remove main.cpp Add your files

Sign up to request clarification or add additional context in comments.

1 Comment

@user2851616: I'm glad I could have helped! Please accept the answer if it answers your question. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.