Re: classes, strings, learning in VS.NET
From: Allan Bruce (allanmb_at_TAKEAWAYf2s.com)
Date: 12/02/03
- Previous message: Ron Natalie: "Re: Is it legal that a function pointer to "function with default arguments"?"
- In reply to: Peter van Merkerk: "Re: classes, strings, learning in VS.NET"
- Next in thread: Peter van Merkerk: "Re: classes, strings, learning in VS.NET"
- Reply: Peter van Merkerk: "Re: classes, strings, learning in VS.NET"
- Reply: Christoph Rabel: "Re: classes, strings, learning in VS.NET"
- Reply: Chris Theis: "Re: classes, strings, learning in VS.NET"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 2 Dec 2003 14:13:44 -0000
> --------- main.cpp ---------
> #include "X.h"
> #include "A.h"
>
> int main()
> {
> X x;
> x.foo();
> return 0;
> }
>
> A common solution for this problem is putting include guards in the .h
> files:
>
> --------- X.h ---------
> #ifndef X_H
> #define X_H
>
> class X
> {
> public:
> virtual void foo();
> };
>
> #endif
>
> When the X.h file is seen once inside a translation unit the next time
> it gets included it will skip the definitions and declarations inside
> the X.h file. Most experienced C++ programmers will always put include
> guards in header files, even when leaving those out would not cause
> redefinitions errors at that point in time.
>
Since the OP is using VS, he could merely have
#pragma once
at the top of the headers, thus not needing to check #ifdef etc.
- Previous message: Ron Natalie: "Re: Is it legal that a function pointer to "function with default arguments"?"
- In reply to: Peter van Merkerk: "Re: classes, strings, learning in VS.NET"
- Next in thread: Peter van Merkerk: "Re: classes, strings, learning in VS.NET"
- Reply: Peter van Merkerk: "Re: classes, strings, learning in VS.NET"
- Reply: Christoph Rabel: "Re: classes, strings, learning in VS.NET"
- Reply: Chris Theis: "Re: classes, strings, learning in VS.NET"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]