Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:57:20+00:00 2026-06-09T14:57:20+00:00

I am making a Camera class in c++ that I use for OpenGL. When

  • 0

I am making a Camera class in c++ that I use for OpenGL. When I try to print any variable that was declared in Camera.h, the program crashes. But it does not crash if I set or get the value of the variable What am I doing wrong?

Camera.h

    #ifndef CAMERA_H
    #define CAMERA_H

    class Camera
    {
        public:
            Camera();
            Camera(float xP, float yP, float zP);
            void move(float x, float y, float z);

        protected:
        private:
            float xPos, yPos, zPos;
    };

    #endif // CAMERA_H

Camera.cpp

    #include "Camera.h"
    #include <iostream>
    #include <GL/glut.h>

    using namespace std;

    Camera::Camera()
    {
    }

    Camera::Camera(float xP, float yP, float zP)
    : xPos(xP), yPos(yP), zPos(zP)
    {
    }

    void Camera::move(float x, float y, float z)
    {
        glTranslatef(-x, -y, -z);
        //None of this crashes:
        xPos = 1;
        yPos = xPos;
        //Crashes here:
        cout << "mainCamera x = " << xPos << endl;
    }

The crash message I get is:

opengl.exe has encountered a problem and needs to close. We are sorry for the inconvenience.


Edit

If I put the line float xPos, yPos, zPos; in the public section in Camera.h, and call

    Camera mainCamera(0.0f, 0.0f, 0.0f);
    cout << "mainCamera x = " << mainCamera.xPos << endl;

…in the main.cpp, it works just fine and prints:

mainCamera x = 0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:57:22+00:00Added an answer on June 9, 2026 at 2:57 pm

    Well, I figured it out. And this one was a dumb one. I forgot to include windows.h in Main.cpp, which for some reason weird reason it stopped floats from being printed out (???). It works perfectly now.

    #include <windows.h>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making an application that draws shapes and I use a camera to draw
I am making a app involve the use of camera. However, ipad1 does not
I'm making an app that use the flashlight of the camera. I open the
I'm making an app that does some real time image processing using the camera.
Im making an app that should let the user see video from the camera
Making an adobe flex ui in which data that is calculated must use proprietary
I am looking at making an app that uses a camera to measure the
So, I'm making a 3rd person game in XNA. I've created a camera that
I am making an android app that uses the inbuilt camera in the tablet/phone.
I'm making an android 1.6 app that uses phone's camera. In order to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.