Placing Code in Different Files

Hello! I am currently learning how to place code in different files but for whatever reason it says that speak () is not defined in my main. Any suggestions as to why this is happening?

orig.cpp
1
2
3
4
5
6
7
8
9
#include <iostream>
#include "cat.h"

int main ()
{
	speak (); 
	
	return 0; 
}


cat.h
1
2
3
4
5
6
#ifdef CAT_H
#define CAT_H

void speak (); 

#endif 


cat.cpp
1
2
3
4
5
6
7
#include <iostream>
#include "cat.h"

void speak ()
{
	std::cout << "meow" << std::endl;
}


And I try to compile it by writing g++ orig.cpp cat.cpp. However, this returns the error. Not sure why. Any suggestions?
Last edited on
Use #ifndef instead of #ifdef.
Last edited on
Topic archived. No new replies allowed.