News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Undefined Reference to Class In Seprate Folder

Started by jason97931, July 02, 2015, 06:37:17 PM

Previous topic - Next topic

jason97931

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:



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

using namespace std;

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

    const Sally constObj;
    constObj.printShiz2();
}



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

Sally.h:



#ifndef SALLY_H
#define SALLY_H


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

#endif // SALLY_H



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



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.

BlueHazzard

#1
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

scarphin

Did you add 'Sally.h' and 'Sally.cpp' files to your project?

jason97931

As it says at the bottom, they are all in my project and also in the same folder.

scarphin

Will you please post your build log and in code tags?

jason97931

Alright after doing nothing it decided to randomly work. I didn't change anything, I just tried it again and it fixed itself.