class HelloClass(){ //*Error: expected unqualified -id before ')' token
public:
void saying(){
cout <<"hi" <<endl;
}
};
int main(){
HelloClass() HelloObject;
HelloObject.saying;
return 0;
}
hello i am relatively new to c++ and lately i have been trying to tackle classes/objects. At line 5 it says i have an error. I have been continually having this problem with any basic class i try to create. If anybody could explain this, i would be greatly appreciative
class ai {
private:
int row, collumn, returncordiate[2];
//row, collumn
char aimap[6][6];
public:
ai();
bool check(int i, int j){
if(aimap[i][j] == 'S') returntrue;
elsereturnfalse;
}
int passive1(){
srand(time(0));
returncordiate[0] = rand()%7;
return returncordiate[0];
}
int passive2(){
srand(time(0));
returncordiate[1] = rand()%7;
return returncordiate[1];
}
};
ai::ai(){
std::ifstream ship_location;
ship_location.exceptions(std::ifstream::failbit | std::ifstream::badbit);
//open file
try{
ship_location.open("/Users/home/Desktop/battleship/battleship/ship.txt");
}
//catch error
catch (std::ofstream::failure &e){
std::cout << "An error has occured";
ship_location.close();
}
//upload array
for(int j = 0; j < 6; j++){
for(int i = 0; i < 6; i++){
ship_location >> aimap[j][i];
}
}
ship_location.close();
}
some code i found on my computer. has a class with a few functions, a constructor, and private/public setup.
this is how you would declare the object. ai boss;