Weird class problem!

This is a discussion on Weird class problem! within the C++ Programming forums, part of the General Programming Boards category; I am having a class named EFX_Camera defined like this: Code: struct EFX_CameraSystem { EFX_VECTOR3 position; EFX_VECTOR3 lookat; }; class ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    Weird class problem!

    I am having a class named EFX_Camera defined like this:
    Code:
    struct EFX_CameraSystem
    {
        EFX_VECTOR3 position;
        EFX_VECTOR3 lookat;
    };
    
    class EFX_Camera
    {
        public:
        void SetPosition(EFX_VECTOR3 Pos);
        void SetLookAt(EFX_VECTOR3 LookAt);
    
        private:
        EFX_CameraSystem   system;
    };
    The EFX_VECTOR3 is a class with a constructor EFX_VECTOR3(float x, float y, float z) that passes the parameters values in the class member variables f_x, f_y, f_z.

    But I get the error EFX_Camera no approproate default constructor available. (VC++6)

    I do not need a constructor for this, but even if I add one, I get this error: EFX_CameraSystem no appropriate constructor available.

    Please help, I do not know how to fix this. It is weird.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    If you add a construtor that takes params, and you wish to use a default constructor, then you must explicitly include one.....the compiler will not do it for you in these circumstances.
    Code:
    struct EFX_VECTOR3{
    	EFX_VECTOR3(float x,float y,float z){fx=x;fy=y;fz=z;}
    	EFX_VECTOR3(){fx=fy=fz=0;}
    	float fx,fy,fz;
    };

    >>I do not need a constructor for this

    Ah...but you do!

    Code:
    struct EFX_CameraSystem
    {
        EFX_VECTOR3 position;
        EFX_VECTOR3 lookat;
    };
    Each of these members are relying on a default constructor
    Last edited by Fordy; 09-25-2002 at 06:02 AM.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Oh thank you. I haven't thought of it.
    Well, here is one more thing to my list of C++ knowledge
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. template class default constructor problem
    By kocika73 in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2006, 09:42 PM
  4. static class problem.
    By Sebastiani in forum C++ Programming
    Replies: 3
    Last Post: 10-16-2002, 03:27 PM
  5. Replies: 3
    Last Post: 12-03-2001, 12:45 PM

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