Code :: Blocks 10.05未定义的函数引用

时间:2013-01-23 16:25:05

标签: c++ codeblocks

我目前正在使用Code :: Blocks IDE 10.04进行简单的类示例。在创建新类时遇到undefined reference to myClass::myClass()错误。帮我弄清楚错误。

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 个答案:

答案 0 :(得分:3)

由于linking error而发生此错误。稍后我创建新项目(根据问题上面的chris comment)并向项目编译成功添加类。