#include <iostream>
#include <limits>
#include <string>
using namespace std;
void wczytajOsobe(string imie[], string nazwisko[], int wiek[])
{
int i=2;
for(int indeks=0;i>indeks;indeks++)
{
cout << "Podaj Imie: " << endl;
getline(cin, imie[indeks]);
cout << "Podaj Naziwsko: " << endl;
getline(cin, nazwisko[indeks]);
}
}
void wypiszOsobe(string imie[], string nazwisko[], int wiek[])
{
int i=2;
for(int indeks=0;i>indeks;indeks++)
{
cout << imie[indeks];
cout << nazwisko[indeks];
cout << wiek[indeks];
}
}
int main()
{
string imie[2];
string nazwisko[2];
int wiek[2];
for( int i = 0; i < 2; i++ )
wczytajOsobe(imie[i], nazwisko[i], wiek[i]);
for( int i = 0; i < 2; i++ )
wypiszOsobe(imie[ i ], nazwisko[ i ], wiek[ i ] );
system("PAUSE");
return 0;
}
This is my code and i have problem with|36|error: cannot convert 'std::__cxx11::string {aka std::__cxx11::basic_string}' to 'std::__cxx11::string* {aka std::__cxx11::basic_string}' for argument '1' to 'void wczytajOsobe(std::__cxx11::string, std::__cxx11::string*, int*)'|
can somebody help me with that issue ?
You have two functions defined as:
void wczytajOsobe(string imie[], string nazwisko[], int wiek[]);
void wypiszOsobe(string imie[], string nazwisko[], int wiek[]);
Because arrays decay to pointers when passed to functions, the parameter types are actually:
void wczytajOsobe(string *imie, string *nazwisko, int *wiek);
void wypiszOsobe(string *imie, string *nazwisko, int *wiek);
When you call the functions like:
for( int i = 0; i < 2; i++ )
wczytajOsobe(imie[i], nazwisko[i], wiek[i]);
You're not passing arrays but individual array elements. That's why the error message says it can't convert std::string to std::string*.
You don't need those loops in main(). You can just call the functions as:
int main()
{
string imie[2];
string nazwisko[2];
int wiek[2];
wczytajOsobe(imie, nazwisko, wiek);
wypiszOsobe(imie, nazwisko, wiek);
system("PAUSE");
return 0;
}
Note that I'm just passing the arrays to the functions.
Related
I've written this program that's supposed to solve a wheel with numbers from 1 to 11 and I'm having trouble with figuring out what's causing this Linker error. I believe I have everything else working fine in the code body except for this Boolean function that uses an integer array, but the error that comes up says the following. I'm not sure what I've done wrong with the function. I've declared it using a prototype in the beginning of the code, I call the function using its proper name and calling the array correctly. Could someone please help me figure out what's wrong with the code?
undefined reference to 'matchingSums(int)' … relocation truncated to fit: R_X86_64_PC32 against undefined symbol
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <time.h>
using namespace std;
const int MAX_CIRCLES = 11;
const int CENTER_CIRCLE_INDEX = 10;
bool matchingSums(int);
void fillTheWheel(int []);
void displayWheelContents(int []);
void randomizeTheContents(int, int []);
int nbrOfItems, firstSum, nextSum;
int main(void)
{
srand(time(NULL));
int wheel[MAX_CIRCLES];
int numInt = 0;
fillTheWheel(wheel);
while (!matchingSums(*wheel))
{
numInt++;
randomizeTheContents(MAX_CIRCLES, wheel);
}
cout << "After " << numInt << " unsuccessful attempts, the following solution was found:" << endl;
displayWheelContents(wheel);
}
void fillTheWheel(int wheel[])
{
for (int fillTheWheelIndex = 0; fillTheWheelIndex < MAX_CIRCLES; fillTheWheelIndex++)
{
wheel[fillTheWheelIndex] = (fillTheWheelIndex + 1);
}
}
void displayWheelContents(int wheel[])
{
cout << "* Outside circles (clockwise from the top):" << endl << " " << endl;
for (int wheelIndex = 0; wheelIndex < MAX_CIRCLES; wheelIndex++)
{
// Print each value in a column width of 4 as shown in the example-program-execution.txt file
cout << setw(4) << wheel[wheelIndex] << " ";
}
cout << " " << endl << " " << endl << "*Center circle: " << wheel[CENTER_CIRCLE_INDEX] << endl;
}
void randomizeTheContents(int nbrOfItems, int table[])
{
for (int indexA = 0; indexA < nbrOfItems; indexA++)
{
int indexB = rand() % nbrOfItems;
int temp = table[indexA];
table[indexA] = table[indexB];
table[indexB] = temp;
}
}
bool matchingSums(int wheel[])
{
const int MAX_OUTER_CIRCLES = MAX_CIRCLES - 1;
const int OPPOSITE_SIDE_FACTOR = 5;
const int STARTING_INDEX = 0;
int firstSum;
int nextSum;
// Calculate the sum of the first pair of numbers
firstSum = wheel[STARTING_INDEX] + wheel[CENTER_CIRCLE_INDEX]
+ wheel[STARTING_INDEX + OPPOSITE_SIDE_FACTOR];
// Compare the first sum to each of the sums of the other pairs
for (int i = 1; i < MAX_OUTER_CIRCLES/2; i++)
{
nextSum = wheel[i] + wheel[CENTER_CIRCLE_INDEX] + wheel[i + OPPOSITE_SIDE_FACTOR];
if (firstSum != nextSum)
return false;
} // End for
return true;
} // End matchingSums
Initially the function is declared with a parameter of the type int like
bool matchingSums(int);
And called with an argument of the type int in main
while (!matchingSums(*wheel))
But in its definition it is declared with a parameter of the type int [] that is implicitly adjusted by the compiler to the type int * like
bool matchingSums(int wheel[])
So the compiler issues an error because it did not find the definition of the function declared like
bool matchingSums(int);
The argument of matchingsums is of int type but the definition of the matchingSums function accepts int wheel[], an integer type of unsized array.
You must have overlooked this, since the function fillTheWheel accepts the same type of argument but was declared and defined just fine.
Replace the prototype
bool matchingSums(int) to bool matchingSums(int []).
I have a problem with my code. Unfortunately, when compiling I get these errors all the time. What can this be caused by and how to fix it?
error C3861: 'print': identifier not found
My code:
main.cpp
#include "pojazdy.h"
#include <iostream>
using namespace std;
int main()
{
Pojazdy** poj;
int size{ 0 }, index{ 0 };
Petla(poj, size);
print(poj, size);
wyrejestruj(poj,size,0);
print(poj, size);
wyrejestruj(poj,size);
return 0;
}
pojazdy.h
#ifndef pojazdy_h
#define pojazdy_h
#include <iostream>
#include <cstdlib>
using namespace std;
class Pojazdy
{
public:
string typ;
string marka;
string model;
string z_dod;
int ilosc;
int cena;
void dodaj();
void d_pojazd(Pojazdy**& pojazdy, int& size);
void wyrejestruj(Pojazdy**& pojazdy, int& size, int index);
void print(Pojazdy** pojazdy, int size);
void Petla(Pojazdy**& p, int& size);
//void wyswietl();
int get_ilosc() { return ilosc; }
string get_typ() { return typ; }
string get_marka() { return marka; }
string get_model() { return model; }
int get_cena() { return cena; }
void set_ilosc(int x);
};
#endif
pojazdy.cpp
#include "pojazdy.h"
#include <iostream>
using namespace std;
void Pojazdy::set_ilosc(int x) { ilosc = x; }
void Pojazdy::dodaj()
{
cout << "DODAWANIE POJAZDU..." << endl;
cout << "Podaj typ pojazdu:";
cin >> typ;
cout << "Podaj marke pojazdu: ";
cin >> marka;
cout << "Podaj model pojazdu: ";
cin >> model;
cout << "Dodaj cene pojazdu: ";
cin >> cena;
}
void Petla(Pojazdy**& p, int& size) {
char z_dod;// = 'N';
do {
d_pojazd(p, size); //odpowiada za dodawnie
p[size - 1]->dodaj();
cout << "Czy chcesz zakonczyc dodawanie? Jesli tak, wcisnij Y/N: ";
cin >> z_dod;
} while (z_dod == 'N' || z_dod == 'n');//while (p[size]->z_dod == "N" ||p[size]->z_dod == "n");
}
void print(Pojazdy** pojazdy, int size) {
std::cout << "====================================" << std::endl;
for (int i{ 0 }; i < size; i++)
std::cout << "Typ: " << pojazdy[i]->get_typ() << " Marka: " << pojazdy[i]->get_marka() << " Model: " << pojazdy[i]->get_model() << " Cena: " << pojazdy[i]->get_model() << std::endl;
}
void wyrejestruj(Pojazdy**& pojazdy, int& size) {
for (size_t i{ 0 }; i < size; i++)
delete pojazdy[i];
delete[] pojazdy;
size = 0;
pojazdy = NULL;
}
void wyrejestruj(Pojazdy**& pojazdy, int& size, int index) {
if (index < size) {
Pojazdy** temp = new Pojazdy * [size - 1];
short int j{ -1 };
for (size_t i{ 0 }; i < size; i++) {
if (i != index) {
j++;
temp[j] = pojazdy[i];
}
}
delete[] pojazdy;
--size;
pojazdy = temp;
}
else
std::cout << "Pamiec zwolniona!" << std::endl;
}
void d_pojazd(Pojazdy**& pojazdy, int& size) {
Pojazdy** temp = new Pojazdy * [size + 1];
if (size == 0)
temp[size] = new Pojazdy;
else {
for (int i{ 0 }; i < size; i++)
temp[i] = pojazdy[i];
delete[] pojazdy;
temp[size] = new Pojazdy;
}
++size;
pojazdy = temp;
}
I used #ifndef, #define, #endif and #pragma once, but none of them work. I will be really grateful for every code, I am already tired of this second hour. And forgive the non-English variables and function names for them - it's university code, so I didn't feel the need.
Move the functions below outside the class declaration.
void wyrejestruj(Pojazdy**& pojazdy, int& size, int index);
void print(Pojazdy** pojazdy, int size);
void Petla(Pojazdy**& p, int& size);
Or make them static and call like Pojazdy::print(poj, size);.
You declared a non-static member function print in the class definition
class Pojazdy
{
public:
// ...
void print(Pojazdy** pojazdy, int size);
//...
but you are trying to call it as a stand-alone function in main
print(poj, size);
So the compiler issues an error.
The declaration of the function as a stand alone function that at the same time is its definition in the file pojazdy.cpp is not visible in the module with main because this module includes only the header with the class declaration.
You should decide whether this function should be a member function of the class or a stand alone function.
You are not calling your member functions correctly. print can only be called on an object of type Pojazdy, so you need to do something like:
Pojazdy** poj;
int size{ 0 }, index{ 0 };
Pojazdy x; // Creates an object of Pojazdy called z
x.print(poj,size); // Calls the print method on x
Alternatively, if you don't want to have to declare an object, you could make the method static and just call it on the class.
In the .h file:
static void print(Pojazdy** pojazdy, int size);
And then in main:
Pojazdy** poj;
int size{ 0 }, index{ 0 };
Pojazdy::print(poj, size); // Calls the print method on the class
You put your function prototypes in the wrong place. They should be after the class decalration.
class Pojazdy
{
...
};
void print(Pojazdy** pojazdy, int size);
void wyrejestruj(Pojazdy**& pojazdy, int& size);
etc.
print is not a member of the Pojazdy class, so it's wrong to put the prototype inside the Pojazdy class declaration.
I need help... appropriate questions have been asked in the comments. The programs has zero compiler errors and warnings!! I have concerns with calling a member function from another member function using function pointers. (To be precise, setMatrixto() is trying to call setElement() function using function pointer)
Plus somehow the "hello there" is not being printed to the console. I was expecting it to show up as output.Maybe the setMatrixto() is not getting called at all!!
Header File definition
#ifndef MATRIXOPERATIONS_H
#define MATRIXOPERATIONS_H
class MatrixOperations;
typedef int (MatrixOperations::*INTFUNC)(int,int);
typedef void (MatrixOperations::*VOIDFUNC)(int,int,int);
class MatrixOperations
{
public:
MatrixOperations();
MatrixOperations(int size);
~MatrixOperations();
//diagonal matrix funtions
void displayMatrixOf(INTFUNC f);
void setMatrixTo(VOIDFUNC f);
int getElement(INTFUNC from, int i, int j);
void setElement(VOIDFUNC to,int i ,int j, int value);
int fromDiagonalArray(int i, int j);
void toDiagonalArray(int i, int j, int value);
protected:
private:
int size;
int* a;
};
#endif // MATRIXOPERATIONS_H
CPP Implementation File
#include "MatrixOperations.h"
#include <iostream>
using namespace std;
MatrixOperations::MatrixOperations()
{
//ctor
size = 3;
a = new int[size];
}
MatrixOperations::MatrixOperations(int size)
{
//ctor
this->size = size;
a = new int[size];
}
MatrixOperations::~MatrixOperations()
{
//dtor
delete[] a;
}
///////////////////FUCNTION POINTER SECTION///////////////////////////////////
int MatrixOperations::getElement(INTFUNC from, int i, int j)
{
return (this->*from)(i,j);
}
void MatrixOperations::setElement(VOIDFUNC to,int i ,int j, int value)
{
(this->*to)(i,j,value);
}
/////////////////////////////////DIAGONAL ARRAY OPERATIONS/////////////////////////////////////////////////
int MatrixOperations::fromDiagonalArray(int i, int j)
{
if(i==j)
{
return a[i];
}
else
{
return 0;
}
}
void MatrixOperations::toDiagonalArray(int i, int j, int value)
{
a[i] = value;
}
///////////////////////////////////////////////////////////////////
void MatrixOperations::displayMatrixOf(INTFUNC f)
{
for(int i{0}; i < size; i++)
{
for(int j{0}; j < size; j++)
{
cout << getElement(f,i,j) << "\t"; //is this the correct way to send the function pointer?
}
cout << endl;
}
}
void MatrixOperations::setMatrixTo(VOIDFUNC f)
{
cout << "Hello there!!"; //not getting this output.. whats wrong??
for(int i{0}; i < size; i++)
{
int value {};
cout << "Enter value diagonal element " << i << " : ";
cin >> value;
setElement(f,i,i,value); //is this the correct way to send the function pointer?
}
}
///////////////////////////////////////////////////////////////////////////////
Main File
#include <iostream>
#include "MatrixOperations.h"
typedef MatrixOperations MATRIX;
using namespace std;
int main()
{
MATRIX m1;
m1.setMatrixTo(MATRIX::toDiagonalArray); //was expecting a "Hello there!" but i am not getting that output either
return 0;
}
EDIT2: I added all the class definitions and main function in one single file. SURPRISINGLY!! this works . I am confused??!!!
#include <iostream>
using namespace std;
class MatrixOperations;
typedef void (MatrixOperations::*VOIDFUNC)(int,int,int);
typedef MatrixOperations MATRIX;
class MatrixOperations
{
public:
MatrixOperations();
MatrixOperations(int size);
~MatrixOperations();
//diagonal matrix funtions
void setMatrixTo(VOIDFUNC f);
void setElement(VOIDFUNC to,int i ,int j, int value);
void toDiagonalArray(int i, int j, int value);
private:
int size;
int* a;
};
MatrixOperations::MatrixOperations()
{ //ctor
size = 3;
a = new int[size];
}
MatrixOperations::MatrixOperations(int size)
{ //ctor
this->size = size;
a = new int[size];
}
MatrixOperations::~MatrixOperations()
{
//dtor
delete[] a;
}
void MatrixOperations::setElement(VOIDFUNC to,int i ,int j, int value)
{
(this->*to)(i,j,value);
}
/////////////////////////////////DIAGONAL ARRAY OPERATIONS/////////////////////////////////////////////////
void MatrixOperations::toDiagonalArray(int i, int j, int value)
{
a[i] = value;
}
///////////////////////////////////////////////////////////////////
void MatrixOperations::setMatrixTo(VOIDFUNC f)
{
cout << "Hello there!!" << endl;
for(int i{0}; i < size; i++)
{
int value {};
cout << "Enter value diagonal element " << i << " : ";
cin >> value;
setElement(f,i,i,value);
}
}
int main()
{
MATRIX m1;
m1.setMatrixTo(MATRIX::toDiagonalArray);
return 0;
}
There is nothing wrong with the code in both cases. Its just my debugger was not running in admin mode. I got error code 740. So I launched my IDE in admin mode and voila it worked.
In my In-Progress BigInt class, I am having trouble with the declaration of vectors. I am getting the errors:
prog.cpp: In function 'void setBig1(std::string, int)':
prog.cpp:45:3: error: 'big1' was not declared in this scope
big1.push_back(dig[x]);
^
prog.cpp: In function 'voidgetBig1(int)':
prog.cpp:50:11: error: 'big1' was not declared in this scope
cout << big1[x] ;
I believe that my getters and setters involved with the vector big1 are not recognizing the decleration of the vector in the 'public:' portion of the class definition. But I cannot find a solution or a definite reason for the errors. My code is Below:
//my bigInt class
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//class, constructors
//overload operators methods
//add, subtract, multiply, divide
class bigInt{//class
public:
bigInt();
~bigInt();
void setString(string dig);
string getString(void);
int getDigitLength(void);
std::string digit;
int digitLength;
std::string digString;
void setBig1(string dig, int dLength);
std::vector<int> big1;
std::vector<int> big2;
void getBig1(int dLength);
};
//constructors
bigInt::bigInt(void){
std::vector<int> big1;
}
//deconstructor
bigInt::~bigInt(){
}
//getters/setters
void bigInt::setString(string dig){
digit= dig;
digitLength= (digit.length());
}
string bigInt::getString(){
return digit;
}
int bigInt::getDigitLength(){
return digitLength;
}
void setBig1(string dig, int dLength){
for(int x= 0; x<(dLength); x++)
{
big1.push_back(dig[x]);
}
}
void getBig1(int dLength){
for(int x= 0; x<(dLength); x++){
cout << big1[x] ;
}
}
int main(){
string digString= "1"; //string
bigInt my_int{};
//bigInt big1<int>;
my_int.setString(digString); //setInternalString to equal digString
cout << my_int.getString() << endl; //prints internal string
my_int.setBig1(my_int.getString(), my_int.getDigitLength());//sets big1 vector = to string
my_int.getBig1(my_int.getDigitLength()); //print big1 vector
}
I greatly appreciate any assistance.
You forgot to specify class to which the member functions are defined. Instead of
void setBig1(string dig, int dLength){
for(int x= 0; x<(dLength); x++)
{
big1.push_back(dig[x]);
}
}
void getBig1(int dLength){
for(int x= 0; x<(dLength); x++){
cout << big1[x] ;
}
write
void bigInt::setBig1(string dig, int dLength){
for(int x= 0; x<(dLength); x++)
{
big1.push_back(dig[x]);
}
}
void bigInt::getBig1(int dLength){
for(int x= 0; x<(dLength); x++){
cout << big1[x] ;
}
Also you could declare all getters with qualifier const because they do not change an object itself of the class. For example
class bigInt
{
//...
void getBig1(int dLength) const;
};
void bigInt::getBig1(int dLength) const
{
for ( int i = 0; i < dLength; i++ ) cout << big1[i] ;
}
and in general case instead of type int there is better to use at least type size_t or std::vector::size_type
The vectors themselves could be declared with the access control private.
I'm new in C++
I try to pass array as parameters I can't find a solution.
Here's my code :
My Header code
autobus.h
#ifndef autobus_H
#define autobus_H
#include <iostream>
using namespace std;
class autobus{
public :
int placeautobus[2] [40];
autobus();
void affichageTicket();
int calculdesplaces(int, int);
};
#endif
Bus.cpp
#include <iostream>
#include "autobus.h"
autobus::autobus(){
int i,j;
for (i=0;i<2;i++) {
for (j=0;j<40;j++)
placeautobus[i][j] = 0;
}
};
void autobus::affichageTicket()
{
}
int autobus::calculdesplaces(int typeautobus, int *placeautobus[2][40]){
int placenumero;
for (int place = 0; place < 40; place++){
if ( placeautobus[typeautobus][place] ==0) {
placenumero = place+1;
cout <<"Places : "<< placenumero <<endl;
}
}
return placenumero;
}
finally my main.cpp
#include <cstdlib>
#include <iostream>
#include "autobus.h"
using namespace std;
int main()
{
int TypeAutobus;
autobus *choixautobus = new autobus();
cout << "1 for smoking bus" << endl;
cout << "2 for non-smoking bus" << endl;
cin >> TypeAutobus;
choixautobus->calculdesplaces(TypeAutobus, choixautobus->placeautobus[2][40]);
system("PAUSE");
return EXIT_SUCCESS;
}
Everything works, but when I add this line in my main.cpp :
choixautobus->calculdesplaces(TypeAutobus, choixautobus->placeautobus[2][40]);
I have an error, I try many things.
I just want to call my function calculdesplaces with the variable : choixautobus having array placeautobus.
Can someone know how to do this.
thanks
Like others have said already, the code you have now shouldn't compile right now because of the declaration and definition mismatch for calculdesplaces.
You shouldn't need to pass the placeautobus array at all since it is a member of the autobus class. Just delete your 2nd argument from calculdesplaces and you should be able to do what you want.
int autobus::calculdesplaces(int typeautobus){
int placenumero;
for (int place = 0; place < 40; place++){
if ( placeautobus[typeautobus][place] ==0) {
placenumero = place+1;
cout <<"Places : "<< placenumero <<endl;
}
}
return placenumero;
}
In your class declaration, you need to specify the correct array pointer type for the second parameter of calculdesplaces():
class autobus{
public :
autobus();
void affichageTicket();
int calculdesplaces(int typeautobus, int (*placeautobus)[40]);
int placeautobus[2][40];
};
This declares, that you are passing a pointer to an array of 40 int elements. This is precisely the type to which the 2D array int placeautobus[2][40]; decays when you use its name: When you mention the name of an array, the array name decays into a pointer to its first element. In the case of an array of type int ()[2][40], that is a pointer to the first line array (type is int (*)[40]).
Note that the parentheses in int (*placeautobus)[40] are very important: the array subscript operator [] has a higher precedence than the dereferencing operator *, so int (*placeautobus)[40] means something very different from int* placeautobus[40].
I have also taken the liberty of including the variable names in the method declaration, this provides essential information to the reader, even though the compiler ignores it.
In the implementation of calculdesplaces(), you can access the argument array precisely the same way as you can access any 2D array:
int autobus::calculdesplaces(int typeautobus, int (*placeautobus)[40]) {
int placenumero;
for (int place = 0; place < 40; place++) {
if ( placeautobus[typeautobus][place] ==0) {
placenumero = place+1;
cout <<"Places : "<< placenumero <<endl;
}
}
return placenumero;
}
Now you can easily call your function by just passing the array:
int main() {
int TypeAutobus;
autobus *choixautobus = new autobus();
cout << "1 for smoking bus" << endl;
cout << "2 for non-smoking bus" << endl;
cin >> TypeAutobus;
choixautobus->calculdesplaces(TypeAutobus, choixautobus->placeautobus);
system("PAUSE");
return EXIT_SUCCESS;
}
Note:
The above only fixes the symptoms, not the disease. The actual problem is, that the design of the class itself is flawed. Data members should generally not be public, and methods should work on the data of the object on which they are called, instead of relying on getting parts of the object passed in via additional arguments. So, the class definition should look like this:
class autobus{
public :
autobus();
void affichageTicket();
int calculdesplaces(int typeautobus);
private:
int placeautobus[2][40];
};
The definition of calculdesplaces() doesn't change that much, it just does not shadow the already available array member with a function argument:
int autobus::calculdesplaces(int typeautobus) {
int placenumero;
for (int place = 0; place < 40; place++) {
if ( placeautobus[typeautobus][place] ==0) {
placenumero = place+1;
cout <<"Places : "<< placenumero <<endl;
}
}
return placenumero;
}
And you don't need to "grab into the object" in main(), the array is implicitly passed via the this pointer:
int main() {
int TypeAutobus;
autobus *choixautobus = new autobus();
cout << "1 for smoking bus" << endl;
cout << "2 for non-smoking bus" << endl;
cin >> TypeAutobus;
choixautobus->calculdesplaces(TypeAutobus);
system("PAUSE");
return EXIT_SUCCESS;
}
You haven't mentioned what the error it. But I think this it the issue:
What is the data type of second argument in calculdesplaces function declaration:
int calculdesplaces(int, int);
It is: int
What is the data type of placeautobus[2][40] in calculdesplaces function definition:
int autobus::calculdesplaces(int typeautobus, int *placeautobus[2][40]){ ... }
It is: int*
What is the data type of placeautobus[2][40] in calculdesplaces function call:
choixautobus->calculdesplaces(TypeAutobus, choixautobus->placeautobus[2][40]);
Looking at class autobus { ... }, it is: int
So there is mismatch between the datatype used in function declaration, definition and call. Try solving this.
The code should not be compiled.
The member function declaration of calculdesplaces
int calculdesplaces(int, int);
does not coinside with its definition
int autobus::calculdesplaces(int typeautobus, int *placeautobus[2][40]){
The type of the second parameter differs.
As for the error message then the function should be called as
choixautobus->calculdesplaces( TypeAutobus, choixautobus->placeautobus );
Take into account that the function has a bug. You pass to the function as the first argument either 1 or 2 and use these values as indices of the array while the valid indices are 0 and 1.
Also the function does not need to have the second parameter because it deals with the data member
int placeautobus[2] [40];
So I would define the class and member functions the following way
class autobus{
public :
int placeautobus[2] [40];
autobus();
void affichageTicket();
int calculdesplaces(int);
};
#include <iostream>
#include "autobus.h"
autobus::autobus() : placeautobus {}
{
}
void autobus::affichageTicket()
{
}
int autobus::calculdesplaces( int typeautobus )
{
int placenumero = 0;
for (int place = 0; place < 40; place++)
{
if ( placeautobus[typeautobus - 1][place] == 0 )
{
placenumero = place+1;
cout <<"Places : "<< placenumero <<endl;
break;
}
}
return placenumero;
}
Though I do not understand what you return from the function.:)
Also you could specify the initialization of the array inside the class definition
class autobus{
public :
int placeautobus[2] [40] = {};
//...
In this case the main can look as
int main()
{
int TypeAutobus;
autobus *choixautobus = new autobus();
cout << "1 for smoking bus" << endl;
cout << "2 for non-smoking bus" << endl;
cin >> TypeAutobus;
choixautobus->calculdesplaces( TypeAutobus );
system("PAUSE");
return EXIT_SUCCESS;
}