Cannot create a method in a class

this is your header file Test.h:

  1. happy member was named bhappy_
  2. for a private member think to add a getter and setter public member functions
#ifndef TEST_H_
#define TEST_H_

class Test {
private:
	bool bhappy_;
public:
    Test() // ctor
    virtual ~Test() // dtor
public:
	void makeHappy();
	void makeSad();
	void speak();
};

#endif /* TEST_H_ */

this is your Test.cpp file:

  1. It’s not advised to use using namespace std;
  2. Don’t include your header two times
//.cpp file
#include "Test.h"
#include <iostream>//unresolved inclusion

//ctor
Test::Test() : bhappy_(false)
{}

Test::~Test(){}

void Test::speak() {

    if (bhappy_) {//Symbol hapy could not be resolved
        std::cout << "Meouw!" << endl;
    } else {
        std::cout << "Ssssss!" << endl;
    }
}

void Test::makeHappy() {
    bhappy_ = true;//Symbol hapy could not be resolved
}

void Test::makeSad() { // member decleration not found
    bhappy_ = false;//Symbol hapy could not be resolved
}

This is your main function:

#include "Test.h"

int main(int argc, char** argv) {
    Test jim;
    jim.makeHappy();//method make happy could not be resolved
    jim.speak();//method speak could not be resolved

    Test bob;
    bob.makeSad();//method make happy could not be resolved
    bob.speak();//method speak could not be resolved

    return 0;
}

Leave a Comment