Call class function without creating an object?

Hello people of the world!
This is my glob.h file:
1
2
3
4
5
6
7
8
#ifndef GLOB_H
#define GLOB_H

class ampla{
public:
    void glob_function();
};
#endif // GLOB_H 

And this is my glob.cpp file:
1
2
3
4
5
6
#include <iostream>
#include "glob.h"
using namespace std;
void ampla::glob_function(){
    cout << "Test1\n";
}


In any other .cpp file that my program uses I want to be able to call the glob_function() via ampla::glob_function() but the compiler insists me to do it this way(and it works OK!):
1
2
ampla test;
test.glob_function();

But I want to be able to call it at once, what am I doing wrong?
I don't really understand what you want, so I can recommend you to use static specifier:
1
2
3
4
5
6
7
8
#ifndef GLOB_H
#define GLOB_H

class ampla{
public:
    static void glob_function(); // and everything other is the same
};
#endif // GLOB_H  

To call this function, you should specify ampla::glob_function(); in any part of your code.
Yes, this worked fine, thanks :D
Topic archived. No new replies allowed.