Creating a Header File

I was working on creating a header file to contain useful functions that I defined that seem useful or interesting enough to be used again. Currently it only has two functions. My compiler however, Microsoft Visual Studio, says it laden with errors. I was wondering if someone could help me understand why or how to make this code work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once

template <class T> T operator** (T exponent)
{
	return pow(this, exponent);
}

int fact (int x)
{
	if (x == 1 || x == 0)
		return 1;
	return(x * fact(x - 1));
}

bool isprime(int x)
{
	if (x <= 0)
		return false;
	if (x == 2)
		return true;
	if (x == 1)
		return false;
	for (int i = 2; i < x; i++)
	{
		if (x % i == 0)
			return false;
	}
	return true;
}
>My compiler however, Microsoft Visual Studio, says it laden with errors.
Posting those errors may help.

iirc c++ doesn't have an operator** and you aren't allowed to create your own operators, so I imagine you're getting an error wrt that. Other than that it looks to be fine.
When developing, especially early on - test your code frequently without fully fleshing it out. For instance, while some of the function definitions would pass, not having the include providing your "pow()" declaration.
Thank you the header file is working fine now. I did not know that you could only overload an operator not create a new one. Once I took that there are no problems thanks to both of you.
Topic archived. No new replies allowed.