Re: classes, strings, learning in VS.NET

From: Allan Bruce (allanmb_at_TAKEAWAYf2s.com)
Date: 12/02/03

  • Next message: tom_usenet: "Re: fileToString"
    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.


  • Next message: tom_usenet: "Re: fileToString"