dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: code::blocks malfunction?

  1. #1
    Join Date
    Mar 2008
    Posts
    8

    code::blocks malfunction?

    I am having the oddest problem using code blocks (64 bit ubuntu version). I have been trying to write a program that uses two classes (for now) and code blocks will not compile it. The message it gives is "multiple definition of `p_tree:_tree()" In fact, it gives me that message for every function. If I try and compile the code in the terminal, it works. If I try to compile it in code blocks (without it being a code blocks project) it works. Only when I try to compile it in a project it fails. Here is my code:

    Main.cpp

    #include <iostream>
    #include "p_tree.cpp"
    using namespace std;

    int main()
    {
    int* test;
    p_tree pat;
    test=pat.int_2_bin(10);
    return 0;
    }



    p_tree.cpp:
    #include "p_tree.h"
    #include <iostream>
    using namespace std;

    int* p_tree::int_2_bin(int val)
    {
    int c_s=14;
    int* b_s=new int[c_s];
    for(int i=0;i<c_s;i++)
    {
    if (val%2)
    b_s[i]=1;
    else
    b_s[i]=0;
    val/=2;
    }
    for(int i=0;i<c_s;i++)
    {
    cout<<b_s[i];
    }
    return b_s;
    }

    p_tree:: p_tree()
    {
    }


    p_tree.h

    #ifndef p_tree_h
    #define p_tree_h
    class p_tree
    {
    public:
    int* int_2_bin(int);
    p_tree();
    };
    #endif



    Can somebody please help me?
    Attached Images Attached Images  
    Last edited by piratebill1; April 6th, 2008 at 10:55 PM. Reason: Added attachment

  2. #2
    Join Date
    Aug 2005
    Location
    LI, NY
    Posts
    576

    Re: code::blocks malfunction?

    In main.cpp you're including p_tree.cpp. You want to include p_tree.hpp.

    Don't get in the habit of blaming your compiler (code::blocks is not a compiler by the way) for the problems you encounter. Odds are if you do so, you'll be wrong every time.
    - Alon

  3. #3
    Join Date
    Mar 2008
    Posts
    8

    Re: code::blocks malfunction?

    Your were right, it works now. I have a lot to learn about coding I guess. Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)