undefined reference to 错误
写了一个最小程序,代码如下:class1.h:#ifndefclass1_h#defineclass1_hnamespacemainprogram{classclass1...
写了一个最小程序,代码如下:
class1.h:
#ifndef class1_h
#define class1_h
namespace mainprogram {
class class1
{
public:
class1();
virtual ~class1() { }
};
}
#endif // class1_h
class1.cpp:
# include "class1.h"
namespace mainprogram {
class class1
{
class1 :: class1()
{
cout << "Hello world!" << endl;
}
}
}
main.cpp:
#include <iostream>
#include "class1.h"
using namespace std;
using namespace mainprogram;
int main()
{
cout << "Hello world!" << endl;
class1 c11;
return 0;
}
报错提示:undefined reference to `mainprogram::class1::class1()' 展开
class1.h:
#ifndef class1_h
#define class1_h
namespace mainprogram {
class class1
{
public:
class1();
virtual ~class1() { }
};
}
#endif // class1_h
class1.cpp:
# include "class1.h"
namespace mainprogram {
class class1
{
class1 :: class1()
{
cout << "Hello world!" << endl;
}
}
}
main.cpp:
#include <iostream>
#include "class1.h"
using namespace std;
using namespace mainprogram;
int main()
{
cout << "Hello world!" << endl;
class1 c11;
return 0;
}
报错提示:undefined reference to `mainprogram::class1::class1()' 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询