Code::Blocks 10.05 Undefined reference to function

拈花ヽ惹草 提交于 2019-12-24 05:22:33

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/14484402/codeblocks-10-05-undefined-reference-to-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!