fatal error LNK1120: 1 unresolved externals 如何解决这个问题?

jibee 2008-03-30 11:32:54
#ifndef HEAD_H
#define HEAD_H

class Date {
public:
Date ( int = 1 , int = 1, int = 1990 );
void print() const;
~Date();

private:

int month;
int day;
int year;
int checkDay( int ) const;

};

#endif


#include <iostream>

using std::cout;
using std::endl;

#include "head.h"

Date::Date( int mn, int dy, int yr)
{
if ( mn > 0 && mn <=12 )
month = mn;
else {
month = 1;
cout << "Month " << mn << " invalid. Set to month 1.\n";
}

year = yr;
day = checkDay ( dy );

cout << "Date object constructor for date ";
print ();
cout << endl;
}

void Date::print() const
{

const char *monptr[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
cout << monptr[month-1] <<" " << year << endl;
cout << month << '/' << day << '/' << year <<endl;
cout << monptr[month-1] << " " << day << ',' << " " << year <<endl;

}

Date::~Date()
{
cout << "Date object destructor for date ";
print();
cout <<endl;
}

int Date::checkDay ( int testDay ) const
{
const int daysPerMonth[ 13 ] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
return testDay;
if ( month == 2 && testDay == 29 && ( year % 400 == 0 || ( (year % 4 == 0) && (year % 100 != 0))))
return testDay;

cout << "Day " << testDay << " invalid. Set to day 1.\n";
return 1;
}
...全文
3008 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
所以我把Date命名为CDate,
  • 打赏
  • 举报
回复
发生该连接错误主要是因为Date和SysUtils::Date()命名冲突。
  • 打赏
  • 举报
回复
//main------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

//---------------------------------------------------------------------------
#include "Head.h"
#include <stdio.h>

#pragma argsused
int main(int argc, char* argv[])
{
CDate date;
date.print();
getchar();
return 0;
}
//---------------------------------------------------------------------------
  • 打赏
  • 举报
回复
//Head.cpp------------------------------------------------------------------------
#pragma hdrstop

#include "Head.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)
#include <iostream>

using std::cout;
using std::endl;
CDate::CDate( int mn, int dy, int yr)
{
if ( mn > 0 && mn <=12 )
month = mn;
else {
month = 1;
cout << "Month " << mn << " invalid. Set to month 1.\n";
}

year = yr;
day = checkDay ( dy );

cout << "Date object constructor for date ";
print ();
cout << endl;
}

void CDate::print() const
{

const char *monptr[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
cout << monptr[month-1] <<" " << year << endl;
cout << month << '/' << day << '/' << year <<endl;
cout << monptr[month-1] << " " << day << ',' << " " << year <<endl;

}

CDate::~CDate()
{
cout << "Date object destructor for date ";
print();
cout <<endl;
}

int CDate::checkDay ( int testDay ) const
{
const int daysPerMonth[ 13 ] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
return testDay;
if ( month == 2 && testDay == 29 && ( year % 400 == 0 || ( (year % 4 == 0) && (year % 100 != 0))))
return testDay;

cout << "Day " << testDay << " invalid. Set to day 1.\n";
return 1;
}
  • 打赏
  • 举报
回复
//Head.h
#ifndef HEAD_H
#define HEAD_H
class CDate{
public:
CDate ( int = 1 , int = 1, int = 1990 );
void print() const;
~CDate();

private:

int month;
int day;
int year;
int checkDay( int ) const;

};

#endif
我啃 2008-03-30
  • 打赏
  • 举报
回复
main函数?
  • 打赏
  • 举报
回复
我编译过,没有问题。是不是编译器的Include path 和Library path 有问题。

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧