0

The code can do the talking.

main.cpp

#include "test.h"

#include <iostream>
#include <string>

#define NL "\n"     //"NL" = "New Line"(move the pointer to the next line)
#define SL "\n\n"   //"SL" = "Skip Line"(move the pointer 2 lines)

int main()
{
    Cool_Object.cool_function();

    return 0;
}

test.h

#ifndef TEST_H
#define TEST_H

class Cool_Class
{
    public:
        void cool_function();
};

#endif

test.cpp

#include "test.h"

#include <iostream>
#include <string>

#define NL "\n"     //"NL" = "New Line"(move the pointer to the next line)
#define SL "\n\n"   //"SL" = "Skip Line"(move the pointer 2 lines)

Cool_Class Cool_Object; //WHY CAN'T THIS WORK!!!

Cool_Object.cool_function()
{
    std::cout << "SPRING!!!" << NL;
}

OK, so if I create the object in "main.cpp" it works, but there must be another way, right. All objects ever created cannot have all been created in the file containing "main()" can it?

The error I get is something like "Cool_Object was not declared in this scope".
So what is the problem here? Is it just Code::Blocks(I use Code::Blocks) that sucks or what? lol...

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by ItecKid
0

Hi,

Your declaration of member functions is wrong in the test.cpp Should be like void Cool_Class::cool_function() Also, it has been a while since I do OOP in C++ but I think you also need to declare a constructor, so the object knows how to exist...

Edited by ItecKid: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.