header file question

1
2
3
4
5
6
7
8
9
10
11
12
13
//tclock.h
#ifndef CLOCK_CLASS
#define CLOCK_CLASS
class clock{
public:
clock();
void settime(int newh=0,int newm=0,int news=0);
void showtime();
private:
int hour,minute,second;
};
void f(clock);
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//tclock.cpp
#include<iostream>
#include"tclock.h"
using namespace std;
clock::clock(){
  std::cout<<"clock()"<<std::endl;
}
void clock::settime(int newh,int newm,int news){
  hour=newh;
  minute=newm;
  second=news;
}
void clock::showtime(){
  std::cout<<hour<<":"<<minute<<":"<<second<<std::endl;
}
void f(clock c){//error: variable or field ‘f’ declared void
}


when i compile the above two files, it is error:variable or field ‘f’ declared void.
But if i separate the f as f.h and f.cpp with essentially the same thing in tclock.h and tclock.cpp,

1
2
3
4
5
6
//tf.h
#ifndef TF_H
#define TF_H
#include "tclock.h"
void f(clock);
#endif 


1
2
3
4
//tf.cpp
#include "tf.h"
void f(clock c){
}


then no error!
why???
any comments?
thanks a lot.
i knew it. i need to rename class clock as something else.
Topic archived. No new replies allowed.