Pointers and Refences

This is a discussion on Pointers and Refences within the C++ Programming forums, part of the General Programming Boards category; I'm working on a simple set of classed to represent predicate logic. While I was writing the first few bits ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Location
    UK
    Posts
    109

    Pointers and Refences

    I'm working on a simple set of classed to represent predicate logic. While I was writing the first few bits I ran across something strange.
    My Particle class has a copy constructor defined as:
    Code:
    Particle(const Particle& p)
    When I passed (as a random test) a pointer to this constructor it worked perfectly instead of causing the expected compiler error.
    I tried writing a skeleton class to reproduce the effect (called A in the files) so I could post it here for explanations but this class causes the compiler to produce this error
    Code:
    main.cpp: In function `int main()':
    main.cpp:63: error: no matching function for call to `A::A(A*&)'
    main.cpp:11: note: candidates are: A::A(const A&)
    main.cpp:7: note:                 A::A()
    I then tried the same thing with the assignment operator and obtained exactly the same results: Particle works and A fails.

    Below are links to the source files. I didn't post the directly because it's rather long.

    main.cpp
    logic.h
    logic_proposition.h
    logic_particle.h

    [edit]
    I just realised I forgto to include the settings.h file which is only 2 #defines:
    #define SETTING_PRINTABLE
    #define SETTING_DEBUG

    if #include "settings.h" is removed the code will still work except for the commented out test() function, just without the debug output
    [/edit]
    Last edited by sigfriedmcwild; 07-08-2005 at 02:18 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,325
    My guess is that it is converting the pointer to a bool and using the constructor for Particle that takes a bool. If you comment out that constructor it would probably not work any more.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Location
    UK
    Posts
    109
    You are right. It should have been obvious from the debug output.
    Thanks, I've spent far too much time on this.

Popular pages Recent additions subscribe to a feed

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