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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:51:05+00:00 2026-06-11T19:51:05+00:00

I’m new to OO based programming, so a silly question: I’ve created a class

  • 0

I’m new to OO based programming, so a silly question:

I’ve created a class called algorithmObject. Basically, it has a bunch of functions associated with it.

I’ve created a QT GUI and I want to create a public object of type algorithmObject, since I want to be able to access the member functions in various onClick events.

So in my GUI.h file, I have:

public:

algorithmObject Object1;

In my GUI.cpp file, I’m trying to initialize it by:

 Object1 = algorithmObject();

I’m using MS VS 2010 and I get a compiler error:

error C1903: unable to recover from previous error(s); stopping compilation
error C2065: ‘Object1’ : undeclared identifier

If I don’t include :

Object1 = algorithmObject();

in my GUI.cpp file and just hope for the GUI constructor to create the object for me, I get the same error.

I guess, I am not initializing my object correctly in the .cpp file somehow. Can someone suggest what is the right process?

My algorithmObject files are outlined below:

algorithmObject.h

#include <iostream>
#include <fstream>

class algorithmObject 
{

public:

algorithmObject (void);
~algorithmObject (void);

void function1 (int parameter);
void function2 ();
}

algorithmObject.cpp

#include "algorithmObject.h"

algorithmObject::algorithmObject(void)
{
}

void algorithmObject::function1(int parameter)
{
//do something
}

void algorithmObject::function2()
{
//do something
}

algorithmObject::~algorithmObject(void)
{
}

If I however, don’t include any definition in the GUI.h file and just define my algorithmObject within a single function in the GUI (algorithmObject Object1;) , I am able to correctly access the functionality of my class. But the problem is that the object is local to that function and I cannot access it from any other functions of the GUI.cpp file which is extremely crucial for me …

  • 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-11T19:51:06+00:00Added an answer on June 11, 2026 at 7:51 pm

    You need to include algorithmObject.h in gui.h, so by the time the compiler sees the code that tries to use an algorithmObject, it’s already seen the declaration for the algorithmObject class.

    It’s possible to avoid this by always including algorithmObject.h in the source file before you try to use it, so you’d need to have:

    #include "algorithmObject.h"
    #include "gui.h"
    

    Although this was fairly standard practice in a lot of C for a long time, I (personally) consider it fairly error-prone and fragile, so I generally prefer that if a header depends on other headers, it includes them itself, so there are no prerequisites to meet when including it in a source file.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
In my XML file chapters tag has more chapter tag.i need to display chapters

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.