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

The Archive Base Latest Questions

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

I’m trying to do up a screen scraping assignment. My cpp works, but I

  • 0

I’m trying to do up a screen scraping assignment. My cpp works, but I don’t know how to integrate my unit testing. I tried to do a bool check unit test for the file validity but it’s giving me this error:

error: cannot call member function 'bool ScreenScrape::getFile()' without object

screenscrape.cpp:

#include "screenscrape.h"

using namespace std;

int main()
{
    ScreenScrape ss;
    int choice;

    ...
    ...

    ss.matchPatternTest();
}

screenscrape.h:

class ScreenScrape
{
    public:
    ScreenScrape();
        void    parserTest(int choice);
        void    matchPatternTest();
        void    setIndexValue(string data, string IndexName);
        void    setIndexChange(string data);
        void    setIndexPercent(string data);
        void    setIndexDate(string data);
        bool    getFile();
    private:
        string IndexName;
        string IndexValue;
        string IndexChange;
        string IndexPercent;
        string IndexVID;
        string IndexCID;
        string IndexPID;
        string IndexDate;
};

bool ScreenScrape::getFile()
{
    string file1 = "yahoofinance.htm";
    char*  file2 = new char [file1.size()+1];   // parse file for c string conversion
    strcpy(file2, file1.c_str());               // converts to c string

    ifstream fin;

    fin.open(file2);
    if(fin.good())
        return true;
    else
        return false;
}

screenscrapetest.cpp:

#include "screenscrapetest.h"
#include "screenscrape.h"

CPPUNIT_TEST_SUITE_REGISTRATION (ScreenScrapeTest);

void ScreenScrapeTest::fileTest()
{
    CPPUNIT_ASSERT(ScreenScrape::getFile());   // test file validity
}

screenscrapetest.h:

#ifndef _SCREENSCRAPETEST_H
#define _SCREENSCRAPETEST_H
#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>
#include "screenscrape.h"

class ScreenScrapeTest : public CppUnit::TestFixture
{
    CPPUNIT_TEST_SUITE (ScreenScrapeTest);
    CPPUNIT_TEST (fileTest);
    CPPUNIT_TEST_SUITE_END ();
    public:
        void fileTest();
};
#endif

I tried to declare “ScreenScrape ss;” under screenscrapetest.h, use an object (ss) to call getFile() but it’s giving me multiples of this error:

/home/user/NetBeansProjects/Assignment1/screenscrape.h:259: multiple definition of `ScreenScrape::getFile()'

I only want to check for file validity with unit testing. Any help will be appreciated.
Thanks in advance!

Regards,
Wallace

  • 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-15T21:53:24+00:00Added an answer on May 15, 2026 at 9:53 pm

    bool ScreenScrape::getFile() is not static, so cannot be called as a static function. You’ll need to either (a) declare it as static or (b) create an instance of ScreenScrape and call getFile() from it.

    Looking at the code, it’s not obvious why this function is a method of the class but perhaps it’s still in the early stages of development. It can also be refactored to remove lots of redundant code:

    bool ScreenScrape::getFile()
    {
        std::ifstream fin("yahoofinance.htm");
        return fin.good();
    }
    

    Don’t forget your include guards in screenscrape.h:

    #ifndef SCREENSCRAPE_H
    #define SCREENSCRAPE_H
    // Class declaration here...
    #endif//ndef SCREENSCRAPE_H
    

    And consider moving the implementation of getFile to the cpp source file. These two steps will prevent you getting the “multiple declaration” errors.

    This will fix your compilation errors, but checking for file validity is not a responsibility of a unit test. Unit tests should not interact with the filesystem.

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

Sidebar

Ask A Question

Stats

  • Questions 483k
  • Answers 483k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer select sm.NAME, sm.AverageScore, sm.best_score, s.SUBJECT from ( SELECT NAME, Avg(SCORE)… May 16, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer That is now a feature in Silverlight 4. Quote: The… May 16, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer As a start, you'd probably want to consider coding against… May 16, 2026 at 6:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.