Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kappa

VC.net question

This topic is 5575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tested this code in one file and it worked, now I would like to split it up in clock.cpp and clock.h like this. clock.h
//clock.h

#ifdef CLOCK_H
	#define CLOCK.H
	class _CClock
	{
	public:
		void set_time(int h, int m, int s);
		int  read_hour();
		int  read_min();
		int  read_sec();
		void write(bool write_sec=true);
		void tick();
	private:
		int hour,
			min,
			sec;
	};
#endif
clock.cpp
#include "clock.h"


	
	void _CClock::set_time(int h, int m, int s)
	{
		hour = h;
		min  = m;
		sec  = s;
	}

	int  _CClock::read_hour()
	{
		return hour;
	}

	int  _CClock::read_min()
	{
		return min;
	}

	int  _CClock::read_sec()
	{
		return sec;
	}

	void _CClock::write(bool write_sec)
	{
		std::cout << std::setw(2) << std::setfill(''0'') << hour;
		std::cout << std::setw(2) << std::setfill(''0'') << min;
		
		if(write_sec)
			std::cout << std::setw(2) << std::setfill(''0'') << sec;
	}

	void _CClock::tick()
	{
		sec = (sec+1)%60;
		
		if(!sec)
		{
			min = (min+1)%60;

				if(!min)
				{
					hour = (hour+1)%24;
				}

		}
	}

and now a get these kind of errors: c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\main.cpp(26): error C2228: left of ''.write'' must have class/struct/union type c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(8): error C2653: ''_CClock'' : is not a class or namespace name c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(10): error C2065: ''hour'' : undeclared identifier c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(11): error C2065: ''min'' : undeclared identifier c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(12): error C2065: ''sec'' : undeclared identifier c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(15): error C2653: ''_CClock'' : is not a class or namespace name c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(20): error C2653: ''_CClock'' : is not a class or namespace name c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(25): error C2653: ''_CClock'' : is not a class or namespace name c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(30): error C2653: ''_CClock'' : is not a class or namespace name c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(32): error C2593: ''operator <<'' is ambiguous C:\Program\Microsoft Visual Studio .NET\Vc7\include\ostream(422): could be ''std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'' with [ _Elem=char, _Traits=std::char_traits ] C:\Program\Microsoft Visual Studio .NET\Vc7\include\ostream(402): or ''std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'' with [ _Elem=char, _Traits=std::char_traits ] C:\Program\Microsoft Visual Studio .NET\Vc7\include\ostream(382): or ''std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'' with [ _Elem=char, _Traits=std::char_traits ] C:\Program\Microsoft Visual Studio .NET\Vc7\include\ostream(362): or ''std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(double)'' with [ _Elem=char, _Traits=std::char_traits ] C:\Program\Microsoft Visual Studio .NET\Vc7\include\ostream(342): or ''std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(float)'' with [ _Elem=char, _Traits=std::char_traits ] C:\Program\Microsoft Visual Studio .NET\Vc7\include\ostream(321): or ''std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'' with [ _Elem=char, _Traits=std::char_traits ] C:\Program\Microsoft Visual Studio .NET\Vc7\include\ostream(301): or ''std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'' with [ _Elem=char, _Traits=s c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(33): error C2593: ''operator <<'' is ambiguous C:\Program\Microsoft Visual Studio .NET\Vc7\include\ostream(422): could be ''std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'' with [ _Elem=char, _Traits=std::char_traits ] c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(36): error C2593: ''operator <<'' is ambiguous c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(39): error C2653: ''_CClock'' : is not a class or namespace name c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(41): error C2296: ''%'' : illegal, left operand has type ''''unknown-type'''' c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(43): error C2171: ''!'' : illegal on operands of type ''''unknown-type'''' c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(45): error C2296: ''%'' : illegal, left operand has type ''''unknown-type'''' c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(47): error C2171: ''!'' : illegal on operands of type ''''unknown-type'''' c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\clock.cpp(49): error C2296: ''%'' : illegal, left operand has type ''''unknown-type'''' c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\main.cpp(11): error C2065: ''_CClock'' : undeclared identifier c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\main.cpp(11): error C2146: syntax error : missing '';'' before identifier ''CClock'' c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\main.cpp(11): error C2065: ''CClock'' : undeclared identifier c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\main.cpp(17): error C2228: left of ''.set_time'' must have class/struct/union type c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\main.cpp(19): error C2228: left of ''.write'' must have class/struct/union type c:\Documents and Settings\Ägaren\Mina dokument\Visual Studio Projects\dos\main.cpp(24): error C2228: left of ''.tick'' must have class/struct/union type /////////////////////////////////////////////////////////// what did I do wrong???

Share this post


Link to post
Share on other sites
Advertisement
You have to use #ifndef, otherwise the file won't be ever included. Everything else looks OK

[edited by - MrAndrew on August 15, 2003 1:49:10 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!