2

I'm currently doing simple class example using Code::Blocks IDE 10.04. On creating new class I encounter undefined reference to myClass::myClass() error. Help me on figuring the error.

myclass.h:

#ifndef MYCLASS_H
#define MYCLASS_H
#include<string>
#include<iostream>
using namespace std;
class myClass
{
    public:
        myClass();
     void showMessage();
        virtual ~myClass();
    protected:
    private:
    string myString;
    int integer;
};

#endif // MYCLASS_H

myclass.cpp:

#include "E:\IOE\VII\Elective-DM\Assignment 2\myClass.h"

myClass::myClass()
{
    //ctor
}

myClass::~myClass()
{
    //dtor
}
void myClass::showMessage()
{
    cout<<"Enter the number ";
    cin>>integer;
    cout<<"Enter the String ";
    cin>>myString;
    cout<<"\nInterger you enter is :-"<<integer<<" and String you enter is "<<myString<<endl;

}

sinpleClass.cpp:

#include<E:\IOE\VII\Elective-DM\Assignment 2\myClass.h>
int main()
{
    myClass myClassObj;
    myClassObj.showMessage();
    return 0;
}
11
  • 1
    Please don't use absolute paths to header files... ever. This is most likely also the problem, since the path has "Assignment 2" in it. Commented Jan 23, 2013 at 16:27
  • @StoryTeller I used according to link here Commented Jan 23, 2013 at 16:29
  • 3
    It's a workaround, not a solution. Furthermore, it was a mistake on their part to even offer that workaround. Don't do it. Commented Jan 23, 2013 at 16:30
  • I have not used Codeblocks for years so I do not remember the details on how it builds projects. However is myclass.cpp included in your project's source files? Commented Jan 23, 2013 at 16:33
  • 1
    Looks like a source file / project management issue. Is your myclass.cpp part of the project? Is it passed to the Linker? Commented Jan 23, 2013 at 16:33

1 Answer 1

3

This error is occurs due to the linking error.Later I create new project (according to chris comment above on question) and add class to it the project compile successfully.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.