Author Topic: Undefined Reference to Class In Seprate Folder  (Read 3308 times)

Offline jason97931

  • Single posting newcomer
  • *
  • Posts: 3
Undefined Reference to Class In Seprate Folder
« on: July 02, 2015, 06:37:17 pm »
Hello, I am at tutorial number 44 in "Bucky's c++ programming tutorials" - const objects and There is an error that I can't figure out.

-------------------------------

Main.cpp:

Code

#include "Sally.h"
#include <iostream>

using namespace std;

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

    const Sally constObj;
    constObj.printShiz2();
}


-------------------------------

Sally.h:

Code

#ifndef SALLY_H
#define SALLY_H


class Sally
{
    public:
        Sally();
        void printShiz();
        void printShiz2() const;
    protected:
    private:
};

#endif // SALLY_H


-------------------------------

Code

Sally.cpp:

#include "Sally.h"
#include <iostream>

using namespace std;

Sally::Sally(){
}

void Sally::printShiz(){
    cout << " I am a regular function" << endl;
}

void Sally::printShiz2() const{
    cout << "I am the constant function" << endl;
}


-------------------------------

As far as I can tell my code is exactly the same as his, but I keep getting this error whenever I try to run ANYTHING with a class in a seperate file.

undefined reference to Sally::Sally
undefined reference to Sally::printShiz
undefined reference to Sally::Sally
undefined reference to Sally::printShiz2() const

Also, they are all in the same project file and same folder on my desktop.
« Last Edit: July 02, 2015, 08:39:22 pm by jason97931 »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Undefined Reference to Class In Seprate Folder
« Reply #1 on: July 02, 2015, 07:18:41 pm »
Hello. A few rules first:
1) If you post code please use code tags (the # symbol in the forum editor)
2) Please read and folow  How do I report a compilation problem on the forums?  from our wiki: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (especially the build log part)

if you don't follow this steps we probably won't be able to help you, because there is missing some essential information...

greetings
« Last Edit: July 02, 2015, 07:20:33 pm by BlueHazzard »

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Undefined Reference to Class In Seprate Folder
« Reply #2 on: July 02, 2015, 07:38:07 pm »
Did you add 'Sally.h' and 'Sally.cpp' files to your project?

Offline jason97931

  • Single posting newcomer
  • *
  • Posts: 3
Re: Undefined Reference to Class In Seprate Folder
« Reply #3 on: July 02, 2015, 08:41:02 pm »
As it says at the bottom, they are all in my project and also in the same folder.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Undefined Reference to Class In Seprate Folder
« Reply #4 on: July 02, 2015, 08:43:05 pm »
Will you please post your build log and in code tags?

Offline jason97931

  • Single posting newcomer
  • *
  • Posts: 3
Re: Undefined Reference to Class In Seprate Folder
« Reply #5 on: July 02, 2015, 08:50:33 pm »
Alright after doing nothing it decided to randomly work. I didn't change anything, I just tried it again and it fixed itself.