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

  • Home
  • SEARCH
  • 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 3334146
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:52:23+00:00 2026-05-17T23:52:23+00:00

Still trying to get back into C++ and fumbling on differences from Java. Can

  • 0

Still trying to get back into C++ and fumbling on differences from Java.

Can anyone tell me what’s wrong here?

Test.h

#ifndef TEST_H
#define TEST_H

class Test {
    public:
        int x, y;
        Test();
        virtual ~Test();
    protected:
    private:
};

#endif // TEST_H

Test.cpp

#include "Test.h"

Test::Test() {
    x = 0;
    y = 28;
}

Test::~Test()
{
    //dtor
}

My main app header (I’m using openFrameworks)

#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "Test.h"

class testApp : public ofBaseApp{

 public:
  void setup();
            [snip]
  Test test_obj;

};

#endif

test_app.cpp

#include "testApp.h"
#include "Test.h"

//--------------------------------------------------------------
void testApp::setup(){
    test_obj = new Test();
}

[snip]

This should be straightforward, right? Define a class Test, declare a variable of class Test (test_obj) in test_app.h and then create an instance and assign it to that variable in the test_app.cpp file.

However I’m getting this error message from the compiler in the assignment line :

error: no match for ‘operator=’ in ‘((testApp*)this)->testApp::test_obj = (operator new(12u), (<statement>, ((Test*)<anonymous>)))’

What am I doing wrong? What am I not understanding here?

  • 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-05-17T23:52:24+00:00Added an answer on May 17, 2026 at 11:52 pm

    You use new with pointers in C++. It is different from Java.

    Your declaration of Test test_obj should be Test* test_obj;

    However, you can declare variable simply on stack like Test test_obj;. Doing this means that you don’t have to new the object, the constructor is automatically called and hence, object is initialized.

    To expand on it a little bit more:

    There are two ways of object creation in C++.

    1. Test test_obj;
    2. Test* test_obj = new Test();

    First one creates an object on the stack and it is automatically destroyed (destructor is called) when object goes out of scope.

    For the second one, the object is created on heap and you have to explicitly call delete on the object to destroy it like this:

    delete test_obj;
    

    Remember, there is no automatic memory management in C++, therefore, you have to remember to delete everything that you create with new.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a mapping for tile/pixel positions in one tiled image dataset
I'm storing GData Event objects from the Google API in a datable (Ok, I
It has been a while since I looked at C (still learning) and I
I'm trying to view a surveillance camera system. The remote access is available through
I'm in a bit of trouble here. I upgraded one of our Winforms products
I've been working on trying to write a function that will grab the POST
While trying to model my domain, I came across the following problem. Let's image
I am trying to understand tail-recursion in Haskell. I think I understand what it
I have an app that only crashes for one of my tester’s - no

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.