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 6160947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:24:19+00:00 2026-05-23T21:24:19+00:00

If I declare an object in my header file, I get a compilation error.

  • 0

If I declare an object in my header file, I get a compilation error. I can, however, construct it in my application’s setup() method, simply by calling Analyzer A(44100., "a", 200);.

If I construct it this way, how do I keep a pointer to it? Won’t the object be inaccessible once the constructor call has gone out of scope?

Or, is there another way I should be getting an instance of this object?

(What I’m used to is putting something like Analyzer A; in my header and then in the cpp putting A = new Analyzer(44100., "a", 200);. This, though, won’t compile.)

Analyzer.hh:

class Analyzer {
  public:
    /// constructor
    Analyzer(double rate, std::string id, std::size_t step = 200);
};

Analyzer.cc:

Analyzer::Analyzer(double rate, std::string id, std::size_t step):
  m_step(step),
  m_rate(rate),
  m_id(id),
  m_window(FFT_N),
  m_bufRead(0),
  m_bufWrite(0),
  m_fftLastPhase(FFT_N / 2),
  m_peak(0.0),
  m_oldfreq(0.0)
{
/* ... */
}

testApp.h:

#include "Analyzer.hh"

class testApp : public ofSimpleApp{
public:

// *This line gives compilation error 
// "No matching function for call to Analyzer::Analyzer()"

      Analyzer A;
    }

testApp.cpp:

void testApp::setup(){

// *This line compiles, but how will I access 
//this object outside of current scope?*
  Analyzer A(44100., "a", 200);
}
  • 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-23T21:24:19+00:00Added an answer on May 23, 2026 at 9:24 pm

    you can initialize constructor type of A
    in constructor of testApp as

    testApp:testApp():A(44100., "a", 200){
    //testApp constructor. 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Cocoa application, in the header file, I declare a NSString ivar: NSString
I have a C# interface with certain method parameters declared as object types. However,
I get this error in my smtdplugin implementation file , when i try to
For the program below i get the following error- Potential leak of an object
If I declare a global variable in a header file and include it in
I have the following structure and object of structure defined in the header file
Is it possible to declare a string at all in a header (.h) file,
Is there anyway to declare an object of a class before the class is
How to declare a static dictionary object inside a static class? I tried public
It's known that you should declare events that take as parameters (object sender, EventArgs

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.