Multiple .cpp files

This is a discussion on Multiple .cpp files within the C++ Programming forums, part of the General Programming Boards category; First, be sure you have used inclusion gaurds in all of your header files. See code posted by major_small for ...

  1. #16
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    First, be sure you have used inclusion gaurds in all of your header files. See code posted by major_small for an example of the necessary syntax if you aren't familiar with it.

    Then, trying to piece things together, in the class declaration for DataAll you declare sqlite_path and user to be static variables with these lines:

    static const char* sqlite_path;
    static Uporabnik user;

    Then you say you do define sqlite_path in all cpp files

    >Here's the code that I use in all .cpp files:

    by doing this:

    >const char* DataAll::sqlite_path = "program.db";

    However, since DataAll::sqlite_path is a static variable, this amounts to multiple definition of sqlite_path, as that sort of statement should only be made once, usually in the header file where DataAll is declared. Again, see major_smalls code for an example. I don't see DataAll::sqlite_path listed in the series of error statements you have posted:

    >I still get an error from linker:

    and I don't see that you do the same sort of thing with DataAll::user as you do with DataAll::sqlite_path in the code you posted, though I do see the multiple definition error for DataAll::user

    >multiple definition of `DataAll::user'

    so I suspect that you are doing the same thing with DataAll::user, and the other static variables that are listed in the error statements posted, that you do with DataAll::sqlite_path and I suspect that there is a multiple definition error statement with DataAll::sqlite_path in it some place in the list of errors that didn't get posted.

    If you want to use a DataAll object in several different cpp files then define the static variables just once, in DataAll.h, as per major_smalls example and include the DataAll.h header file in each file that uses the DataAll object. Then you can use the static variables as you would other variables of the object, again, see major_smalls code for an example.
    You're only born perfect.

  2. #17
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    Thanks guys, you're great! I read the whole thread 3 times and then I finally got up with a working idea!

    Thanks again for all help and answers!!!
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 03-23-2009, 12:30 AM
  2. How to create a C project with multiple source files
    By MSF1981 in forum C Programming
    Replies: 5
    Last Post: 03-22-2009, 10:25 AM
  3. copy multiple files to a destination file
    By Bones in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2003, 11:47 AM
  4. Including multiple .cpp file in project
    By bonkey in forum C++ Programming
    Replies: 2
    Last Post: 11-04-2002, 08:41 AM
  5. opening multiple files sequentially
    By moonwalker in forum C Programming
    Replies: 5
    Last Post: 08-20-2002, 10:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21