Test Program Error

Hello! So I have to write several functions in a program to pass certain tests in a test program, but the first function I am writing is causing me some difficulties.

Here is the function code in the main .cpp file
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include "CS201Final.h"
#include <string>
#include <algorithm>
#include "util.h"

using namespace std;

bool isPermutation(char * ptr1, char * ptr2) // creates a function that checks to see if two arrays are permutations of
                                             // eachother
{
    int comp1 = strlen(ptr1); // gets the length of one array
    int comp2 = strlen(ptr2); // gets the length of the second array
    
    if(comp1 != comp2)
    {
        return false;
    }
    for(int i =0; i<comp1; i++)
    {
        int idx = i;
        {
            for(int j=i; j<comp1-1; i++)
            {
                if(ptr1[j]<ptr1[idx])
                {
                    idx=j;
                }
            }
            swap(ptr1[idx],ptr1[i]);
        }
    }
    for(int i =0; i<comp1; i++)
    {
        int idx = i;
        {
            for(int j=i; j<comp2-1; i++)
            {
                if(ptr2[j]<ptr2[idx])
                {
                    idx=j;
                }
            }
            swap(ptr2[idx],ptr2[i]);
        }
    }
    if(ptr1==ptr2)
    {
        return true;
    }
    else
    {
        return false;
    }
}


Here is the header file:

1
2
3
4
5
6
7
8

#ifndef final_CS201Final_h
#define final_CS201Final_h

bool isPermutation();

#endif


and here is the part of the test program that it should match with

1
2
3
4
5
6
7
8
9
10
11
12
13
14

void testIsPermutation(Tester & t)
{
    cout << "Testing String Conversion Functions:" << endl;
    char * ptr1=(char*)"abcdefg";
    char * ptr2=(char*)"cbdeagf";
    t.test( isPermutation(ptr1,ptr2), "Testing two equal length strings which are permutations");
    t.test(!strcmp(ptr2,(char*)"cbdeagf"), "Testing to see that strings were not altered");
    ptr2=(char*)"abc";
    t.test(!isPermutation(ptr1,ptr2), "Testing strings of differing length");
    ptr1=(char*)"def";
    t.test(!isPermutation(ptr1,ptr2), "Testing unequal strings of same length");
}


The errors I keep receiving in the test program say:

No matching function for call to 'isPermutation'
on lines 7,9,&10 in the test function.

So it's saying that it cannot find the isPermutation function, but why is that?
Hello!
Maybe isPermutation isn't of the same member class of t.
You should declare it static, and see if this works. If you could post all the code, it could be easier to help.
Bye!
Last edited on
Here is the header file:
1
2
3
4
5
6
> #ifndef final_CS201Final_h
> #define final_CS201Final_h

> bool isPermutation();

> #endif 


1
2
3
4
5
6
7
8
#ifndef final_CS201Final_h
#define final_CS201Final_h

// bool isPermutation(); // this is not the function that you have defined

bool isPermutation(char * ptr1, char * ptr2) ; // this is

#endif 


JLBorges, don't forget polimorphysm, but I think that he made the error as you said.
Last edited on
Alrighty! Thanks guys. :)
Topic archived. No new replies allowed.