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;

this is for sally.cpp

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


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

this is for sally.h

#ifndef SALLY_H
#define SALLY_H

class sally
    void tim();


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


- page 1
Oldest  Newest  Rating
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
0 Bernard Pyc0d333 Parah · December 11, 2014
0 Teemmy Ellorry · December 11, 2014
Am not using "Codeblocks" am using "Devc"
0 Teemmy Ellorry · December 11, 2014
I created all files inside a folder.
0 Teemmy Ellorry · December 11, 2014
Someone please rescue me... Have been coding all day trying to figure this out, have tried all what you guys said... its still giving errors... is it because of the compiler am using? "DEVc" I created all files manually unlike "codeblocks" which builds the two files when creating a class. PLEASE HELP!!!
+1 Bernard Pyc0d333 Parah · December 11, 2014
Teemmy sorry was in class.
Since you are using Dev, you can still create a project in Dev.

1.On the main menu, click File -> New Project...
2.On the New Project dialog box, click the Project property sheet if necessary.
3.Click Console Application
4.Click OK.
5.On the subsequent New Project dialog box, type the name of the project
6.Click OK. You will be asked to create a location for the project.
7.Give the project folder a name the folder
 The first c++ program has been created for you(main.cpp)
9.then you can create new classes in the folder 
0 Teemmy Ellorry · December 12, 2014
Will do just that now... I'll get back to you guys soon...
0 Teemmy Ellorry · December 12, 2014
You guys are sweet Thanks a ton @ all... am more than grateful...8-)
0 Bernard Pyc0d333 Parah · December 12, 2014
did it work? you can also thank people by giving them a vote by clicking on the vote button.
But more importantly happy to always help.
-1 justin zodkoy · December 12, 2014
I use code blocks and I just needed to restart my IDE
  • 1
  • 2



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

Bucky Roberts Administrator