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...

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.