Trouble with using functions from classes

I am making a basic brute force program and i am having trouble using functions through classes.

Brute Force.cpp.cpp(I messed up with the name)(Where the main function is):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <string>

#include "Hidden Password.cpp"
#include "Brute Force.cpp"

using namespace std;

int main()
{
	string bruteforce;


	cout << "Enter the name to brute force \n";

	Hidden_Password::Password_Function(brute_force::brute_force_function());
    return 0;
}

Brute Force.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <string>

using namespace std;

static class brute_force {
	int input;

	public:

		int brute_force_function() {
			for (int i = 0; i >= 10000000000;i++) {
				return i;
			}
		}
	};

Hidden Password.cpp:
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
30
31
#pragma once 
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <string>

#include "Hidden Password.cpp"

using namespace std;

	static class Hidden_Password {
	int	private_password = 9265832594;
	int input_password;

	bool correct_password = true;
	
	public:
		
			//function
			int Password_Function(int input_password) {
				while (bool correct_password = true) {
					if (input_password == private_password) {
						bool correct_password = false;
						cout << "You got the password \n";
					}
				}
			}
};




Note-- The problem is in "Brute Force.cpp.cpp" at line 21 where i mention the classes and functions.



Consol:
1>------ Build started: Project: Brute Force.cpp, Configuration: Debug Win32 ------
1>Hidden Password.cpp
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\hidden password.cpp(15): warning C4305: 'initializing': truncation from '__int64' to 'int'
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\hidden password.cpp(15): warning C4309: 'initializing': truncation of constant value
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\hidden password.cpp(31): warning C4091: 'static ': ignored on left of 'Hidden_Password' when no variable is declared
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\hidden password.cpp(14): error C2011: 'Hidden_Password': 'class' type redefinition
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\hidden password.cpp(14): note: see declaration of 'Hidden_Password'
1>Brute Force.cpp.cpp
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\hidden password.cpp(15): warning C4305: 'initializing': truncation from '__int64' to 'int'
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\hidden password.cpp(15): warning C4309: 'initializing': truncation of constant value
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\hidden password.cpp(31): warning C4091: 'static ': ignored on left of 'Hidden_Password' when no variable is declared
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\brute force.cpp(22): warning C4091: 'static ': ignored on left of 'brute_force' when no variable is declared
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\brute force.cpp.cpp(23): error C2352: 'brute_force::brute_force_function': illegal call of non-static member function
1>c:\users\lisa\documents\visual studio 2017\projects\brute force.cpp\brute force.cpp\brute force.cpp(17): note: see declaration of 'brute_force::brute_force_function'
1>Generating Code...
1>Done building project "Brute Force.cpp.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
you have several issues.
first, you typically call a class function by having a variable of the class type:

brute_force bf;
bf.brute_force_function();

Second, return is a total exit.

so

brute_force_function() {
for (int i = 0; i >= 10000000000;i++) {
return i;
}


is just going to return 1 and quit, every time it is called.


I think what you want is this:
constructor for the class sets "current" to zero.
brute_force_function() {return current++}

and then somewhere, main or otherwise, youll call

while(!classinstace.get_correct_password)
classinstance.password_function(bf.brute_force());

or you can connect the classes and have brute_force contain password class instance or a pointer to one and call it directly.

Does this make sense?


also, I highly recommend you test it will a password that like 100 or something. You don't want to have to wait 3 hours for it find the password and wonder if it is working or bugged out.

Last edited on
Topic archived. No new replies allowed.