User forums > Help

Undefined Reference to Class In Seprate Folder

(1/2) > >>

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:


--- Code: ---
#include "Sally.h"
#include <iostream>

using namespace std;

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

    const Sally constObj;
    constObj.printShiz2();
}


--- End code ---

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

Sally.h:


--- Code: ---
#ifndef SALLY_H
#define SALLY_H


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

#endif // SALLY_H


--- End code ---

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


--- 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;
}


--- End code ---

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

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:
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?

Navigation

[0] Message Index

[#] Next page

Go to full version