Errors with classes

I am using CodeBlocks to learn C++. The problem I'm having is I created a class. Like 2 other files, a .cpp and a .h file. I'm getting errors and I don't know why. TIA for your help

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include "NewClass.h"

using namespace std;

int main()
{
    NewClass NC;
    NewClass *NCpointer = &NC;

    NC.printSomething();
    NCpointer->printSomething();
}


NewClass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef NEWCLASS_H
#define NEWCLASS_H


class NewClass
{
    public:
        NewClass();
        void printSomething();
    protected:

    private:
};

#endif 


NewClass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "NewClass.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

NewClass::NewClass()
{
    cout << "OOF" << endl
}

void NewClass::printSomething()
{
    cout << "Something" << endl;
}


errors -
undefined reference to 'NewClass::NewClass()'
undefined reference to 'NewClass::printSomething()'
undefined reference to 'NewClass::printSomething()'
error: id returned 1 exit status
Last edited on
Your CodeBLocks project or whatever COdeBlocks calls it doesn't have NewClass.cpp in it.

Also, NewClass.cpp line 11 is missing a semi-colon. Because the compiler didn't warn you about that, we know for certain that the compiler isn't compiling that file at all.
Ok do you know what I need to do to fix that
Topic archived. No new replies allowed.