Help me figure out my mistake please(classes in separate files)

+1 Teemmy Ellorry · December 11, 2014
This is for main.cpp

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

int main()
{
  sally sallyob;
  sallyob.tim();
}

this is for sally.cpp

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

sally::sally()
{
}

void sally::tim()
{
    cout<<"I love programming"<<endl;
}

this is for sally.h

#ifndef SALLY_H
#define SALLY_H

class sally
{
    public:
        sally();
    void tim();
    protected:
    private:
};

#endif

These are the errors its giving me when i compile and run:
7        F:\WorkShop\C++ Programming\PracticeSpace.cpp    undefined reference to `sally::sally()'
8        F:\WorkShop\C++ Programming\PracticeSpace.cpp    undefined reference to `sally::tim()'
          F:\WorkShop\C++ Programming\collect2.exe    [Error] ld returned 1 exit status

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
0 Bernard Pyc0d333 Parah · December 11, 2014
haha
0 Bernard Pyc0d333 Parah · December 11, 2014
Did you create everything in aproject or you opened the main.cpp as a single file?
if no; do:
1.create a new project
2.go to the source folder in the project and open the main.cpp file
3.then you can  create the sally class and paste the codes accordingly
Because the first and second errors seem like the main.cpp is not connected to the sally class.
let me know what you get
  • 1
  • 2

C++

107,107 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator