Passing objects in functions

When I try to pass an object containing a pointer as member variable in a function within main compiler gives me this warning

obj\Debug\main.o||In function `main':|
D:\programmic++\bigstuff\main.cpp|23|undefined reference to `setValues(std::string, largeIntegers&)'|
D:\programmic++\bigstuff\main.cpp|29|undefined reference to `setValues(std::string, largeIntegers&)'|
||=== Build finished: 2 errors, 0 warnings ===|

Here's my code for main
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
// Somma interi di grandi dimensioni utilizzando la classe largeIntegers.h.
// i numeri vengono letti come array di caratteri. Vanno inseriti al contrario e trasformando ogni cifra in un intero

#include <iostream>
#include "largeIntegers.h"
#include <string>

using namespace std;

void setValues(string, largeIntegers&);             // funzione per inserire i valori

int main()
{
    largeIntegers Intsum;
    string number;

    cout << "Inserire il primo intero:";

    cin >> number;

    largeIntegers Int(number.length());

    setValues(number, Int);

    cin >> number;

    largeIntegers Int2(number.length());

    setValues(number, Int2);

    Int.printInt();

    cout << endl;

    Int2.printInt();

    return 0;
}

void setValues(string Linenum, largeIntegers numint)
{
    int count=0;

    for(int i=Linenum.length()-1; i>=0; i--)
    {
        int digit = Linenum[i]-48;
        numint.insertAt(count,digit);

        count++;
    }
}


for class declaration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef LARGEINTEGERS_H
#define LARGEINTEGERS_H


class largeIntegers
{
    public:
        largeIntegers(int size = 1);
        ~largeIntegers();
        void insertAt(int index, int numb);
        void sumInt(const largeIntegers& otherInt, const largeIntegers& other2Int);
        void minusInt(const largeIntegers& otherInt, const largeIntegers& other2Int);
        void multiInt(const largeIntegers& otherInt, const largeIntegers& other2Int);
        bool isBigger(const largeIntegers& otherInt);
        void printInt() const;
    private:
        int *num;
        int maxSize;
        int length;
};

#endif // LARGEINTEGERS_H 

You declared: void setValues(string, largeIntegers&); , but defined: void setValues(string Linenum, largeIntegers numint).

Note lack of "&" in the line 40. It should be void setValues(string Linenum, largeIntegers & numint)
Last edited on
Thanks a lot!Now it works properly
Topic archived. No new replies allowed.