-1

I'm trying to write a test function for print. Everything compiles fine but why does it not print? what am i doing wrong? can someone please help me out? thanks

oneLine.cpp

#include "oneLine.h"
#include <iostream>


OneLine::OneLine() {

cout << "test";

}

OneLine::~OneLine() {

cout << "~test";

}

oneLine.h

#include <string>
using namespace std;

class OneLine {

    OneLine();
    ~OneLine();
    void breakLine();
    void printReverse();
    istream &readLine(istream& is);
    string returnLine();

private:
    string oneLine;
    char **words;
    int wordCount;
    void resetLine();

};

main.cpp

#include "oneLine.h"

using namespace std;

int main () {

OneLine oLine();


return 0;
}
NewFile
  • 501
  • 5
  • 10
  • 16

1 Answers1

5

This is a function declaration:

OneLine oLine(); // declaration of a function returning a OneLine object

To default construct a OneLine object, you need

OneLine oLine;

or, in C++11, you can also use {}:

OneLine oLine{};

Next, as @POW points out in the comments, your default constructor and destructor have to be made public. Currently they are private.

As an aside, note that using namespace std is considered bad practice, especially in header files.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480