Request for member 'modu18' in f, which is of non-class type 'int'





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















just started off with c++, and stackoverflow for that matter.
any and help infinitely appreciated, apologies in advance if i ask something super dumb



I'm making a program to solve a problem. How many 8 digit numbers are divisible by 18 and are only comprised of the digits 1, 2 and 3. I can generate numbers, but when calling a function i made to use modulus to determine whether they're divisible by 18 or not, the function gives me the error in the title. my code is as follows:



main.cpp



#include <iostream>
#include "functions.h"
using namespace std;

int main()
{
functions f();
for(int a = 1; a<4; a++){
for(int b = 1; b<4; b++){
for(int c = 1; c<4; c++){
for(int d = 1; d<4; d++){
for(int e = 1; e<4; e++){
for(int f = 1; f<4; f++){
for(int g = 1; g<4; g++){
for(int h = 1; h<4; h++){
int number = 10000000*a + 1000000*b + 100000*c + 10000*d + 1000*e + 100*f + 10*g + h; //generates 8 digit numbers, only using the digits 1 2 and 3
cout << number << endl; //prints numbers
int y = 10; //to test this bloody function
cout << f.modu18()(y); //returns 0 or 1 from func
}}}}}}}}}


functions.h



#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <iostream>

using namespace std;

class functions
{
public:
functions();
string modu18(int x);
protected:
private:
};

#endif


functions.cpp



#include "functions.h"
#include <iostream>

using namespace std;

functions::functions(){

cout << "Functions initialised!" << endl; //to see if this thing is actually loading

}

string functions::modu18(int x){ //this is checking whether the number is divisible by 18
if(x % 18 == 0){
return 0;
}else{
return 1;
};
} //btw, using multiple files becuase i want to learn how to make this work for the future


The exact error returned when compiling is



request for member 'modu18' in 'f', which is of non-class type 'int'


I have no clue why this is saying this, all my data types are correct, for the data and the function types.
send help pls
Many thanks.










share|improve this question























  • Why does class functions exist in the first place? You can make modu18 a global free function as well.

    – user10605163
    Nov 16 '18 at 22:56











  • I wanted to put the function in a separate file, so I made a new class in the project and voila. Is there a different way?

    – Kenzi Marcel
    Nov 16 '18 at 23:00











  • Yes, do the same, but without a class. And search a C++ reference for the header to include when you want to use std::string.

    – juanchopanza
    Nov 16 '18 at 23:01











  • "all my data types are correct" -- are you sure about that? For starters, you are returning an integer from a function declared as string ....().

    – CompuChip
    Nov 16 '18 at 23:05













  • I'll try this. Thanks!

    – Kenzi Marcel
    Nov 16 '18 at 23:06


















0















just started off with c++, and stackoverflow for that matter.
any and help infinitely appreciated, apologies in advance if i ask something super dumb



I'm making a program to solve a problem. How many 8 digit numbers are divisible by 18 and are only comprised of the digits 1, 2 and 3. I can generate numbers, but when calling a function i made to use modulus to determine whether they're divisible by 18 or not, the function gives me the error in the title. my code is as follows:



main.cpp



#include <iostream>
#include "functions.h"
using namespace std;

int main()
{
functions f();
for(int a = 1; a<4; a++){
for(int b = 1; b<4; b++){
for(int c = 1; c<4; c++){
for(int d = 1; d<4; d++){
for(int e = 1; e<4; e++){
for(int f = 1; f<4; f++){
for(int g = 1; g<4; g++){
for(int h = 1; h<4; h++){
int number = 10000000*a + 1000000*b + 100000*c + 10000*d + 1000*e + 100*f + 10*g + h; //generates 8 digit numbers, only using the digits 1 2 and 3
cout << number << endl; //prints numbers
int y = 10; //to test this bloody function
cout << f.modu18()(y); //returns 0 or 1 from func
}}}}}}}}}


functions.h



#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <iostream>

using namespace std;

class functions
{
public:
functions();
string modu18(int x);
protected:
private:
};

#endif


functions.cpp



#include "functions.h"
#include <iostream>

using namespace std;

functions::functions(){

cout << "Functions initialised!" << endl; //to see if this thing is actually loading

}

string functions::modu18(int x){ //this is checking whether the number is divisible by 18
if(x % 18 == 0){
return 0;
}else{
return 1;
};
} //btw, using multiple files becuase i want to learn how to make this work for the future


The exact error returned when compiling is



request for member 'modu18' in 'f', which is of non-class type 'int'


I have no clue why this is saying this, all my data types are correct, for the data and the function types.
send help pls
Many thanks.










share|improve this question























  • Why does class functions exist in the first place? You can make modu18 a global free function as well.

    – user10605163
    Nov 16 '18 at 22:56











  • I wanted to put the function in a separate file, so I made a new class in the project and voila. Is there a different way?

    – Kenzi Marcel
    Nov 16 '18 at 23:00











  • Yes, do the same, but without a class. And search a C++ reference for the header to include when you want to use std::string.

    – juanchopanza
    Nov 16 '18 at 23:01











  • "all my data types are correct" -- are you sure about that? For starters, you are returning an integer from a function declared as string ....().

    – CompuChip
    Nov 16 '18 at 23:05













  • I'll try this. Thanks!

    – Kenzi Marcel
    Nov 16 '18 at 23:06














0












0








0








just started off with c++, and stackoverflow for that matter.
any and help infinitely appreciated, apologies in advance if i ask something super dumb



I'm making a program to solve a problem. How many 8 digit numbers are divisible by 18 and are only comprised of the digits 1, 2 and 3. I can generate numbers, but when calling a function i made to use modulus to determine whether they're divisible by 18 or not, the function gives me the error in the title. my code is as follows:



main.cpp



#include <iostream>
#include "functions.h"
using namespace std;

int main()
{
functions f();
for(int a = 1; a<4; a++){
for(int b = 1; b<4; b++){
for(int c = 1; c<4; c++){
for(int d = 1; d<4; d++){
for(int e = 1; e<4; e++){
for(int f = 1; f<4; f++){
for(int g = 1; g<4; g++){
for(int h = 1; h<4; h++){
int number = 10000000*a + 1000000*b + 100000*c + 10000*d + 1000*e + 100*f + 10*g + h; //generates 8 digit numbers, only using the digits 1 2 and 3
cout << number << endl; //prints numbers
int y = 10; //to test this bloody function
cout << f.modu18()(y); //returns 0 or 1 from func
}}}}}}}}}


functions.h



#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <iostream>

using namespace std;

class functions
{
public:
functions();
string modu18(int x);
protected:
private:
};

#endif


functions.cpp



#include "functions.h"
#include <iostream>

using namespace std;

functions::functions(){

cout << "Functions initialised!" << endl; //to see if this thing is actually loading

}

string functions::modu18(int x){ //this is checking whether the number is divisible by 18
if(x % 18 == 0){
return 0;
}else{
return 1;
};
} //btw, using multiple files becuase i want to learn how to make this work for the future


The exact error returned when compiling is



request for member 'modu18' in 'f', which is of non-class type 'int'


I have no clue why this is saying this, all my data types are correct, for the data and the function types.
send help pls
Many thanks.










share|improve this question














just started off with c++, and stackoverflow for that matter.
any and help infinitely appreciated, apologies in advance if i ask something super dumb



I'm making a program to solve a problem. How many 8 digit numbers are divisible by 18 and are only comprised of the digits 1, 2 and 3. I can generate numbers, but when calling a function i made to use modulus to determine whether they're divisible by 18 or not, the function gives me the error in the title. my code is as follows:



main.cpp



#include <iostream>
#include "functions.h"
using namespace std;

int main()
{
functions f();
for(int a = 1; a<4; a++){
for(int b = 1; b<4; b++){
for(int c = 1; c<4; c++){
for(int d = 1; d<4; d++){
for(int e = 1; e<4; e++){
for(int f = 1; f<4; f++){
for(int g = 1; g<4; g++){
for(int h = 1; h<4; h++){
int number = 10000000*a + 1000000*b + 100000*c + 10000*d + 1000*e + 100*f + 10*g + h; //generates 8 digit numbers, only using the digits 1 2 and 3
cout << number << endl; //prints numbers
int y = 10; //to test this bloody function
cout << f.modu18()(y); //returns 0 or 1 from func
}}}}}}}}}


functions.h



#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <iostream>

using namespace std;

class functions
{
public:
functions();
string modu18(int x);
protected:
private:
};

#endif


functions.cpp



#include "functions.h"
#include <iostream>

using namespace std;

functions::functions(){

cout << "Functions initialised!" << endl; //to see if this thing is actually loading

}

string functions::modu18(int x){ //this is checking whether the number is divisible by 18
if(x % 18 == 0){
return 0;
}else{
return 1;
};
} //btw, using multiple files becuase i want to learn how to make this work for the future


The exact error returned when compiling is



request for member 'modu18' in 'f', which is of non-class type 'int'


I have no clue why this is saying this, all my data types are correct, for the data and the function types.
send help pls
Many thanks.







c++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 22:53









Kenzi MarcelKenzi Marcel

195




195













  • Why does class functions exist in the first place? You can make modu18 a global free function as well.

    – user10605163
    Nov 16 '18 at 22:56











  • I wanted to put the function in a separate file, so I made a new class in the project and voila. Is there a different way?

    – Kenzi Marcel
    Nov 16 '18 at 23:00











  • Yes, do the same, but without a class. And search a C++ reference for the header to include when you want to use std::string.

    – juanchopanza
    Nov 16 '18 at 23:01











  • "all my data types are correct" -- are you sure about that? For starters, you are returning an integer from a function declared as string ....().

    – CompuChip
    Nov 16 '18 at 23:05













  • I'll try this. Thanks!

    – Kenzi Marcel
    Nov 16 '18 at 23:06



















  • Why does class functions exist in the first place? You can make modu18 a global free function as well.

    – user10605163
    Nov 16 '18 at 22:56











  • I wanted to put the function in a separate file, so I made a new class in the project and voila. Is there a different way?

    – Kenzi Marcel
    Nov 16 '18 at 23:00











  • Yes, do the same, but without a class. And search a C++ reference for the header to include when you want to use std::string.

    – juanchopanza
    Nov 16 '18 at 23:01











  • "all my data types are correct" -- are you sure about that? For starters, you are returning an integer from a function declared as string ....().

    – CompuChip
    Nov 16 '18 at 23:05













  • I'll try this. Thanks!

    – Kenzi Marcel
    Nov 16 '18 at 23:06

















Why does class functions exist in the first place? You can make modu18 a global free function as well.

– user10605163
Nov 16 '18 at 22:56





Why does class functions exist in the first place? You can make modu18 a global free function as well.

– user10605163
Nov 16 '18 at 22:56













I wanted to put the function in a separate file, so I made a new class in the project and voila. Is there a different way?

– Kenzi Marcel
Nov 16 '18 at 23:00





I wanted to put the function in a separate file, so I made a new class in the project and voila. Is there a different way?

– Kenzi Marcel
Nov 16 '18 at 23:00













Yes, do the same, but without a class. And search a C++ reference for the header to include when you want to use std::string.

– juanchopanza
Nov 16 '18 at 23:01





Yes, do the same, but without a class. And search a C++ reference for the header to include when you want to use std::string.

– juanchopanza
Nov 16 '18 at 23:01













"all my data types are correct" -- are you sure about that? For starters, you are returning an integer from a function declared as string ....().

– CompuChip
Nov 16 '18 at 23:05







"all my data types are correct" -- are you sure about that? For starters, you are returning an integer from a function declared as string ....().

– CompuChip
Nov 16 '18 at 23:05















I'll try this. Thanks!

– Kenzi Marcel
Nov 16 '18 at 23:06





I'll try this. Thanks!

– Kenzi Marcel
Nov 16 '18 at 23:06












1 Answer
1






active

oldest

votes


















0














In your function main there are two different f:



First one here



functions f();


is a variable of type functions or at least that is what you expect (see comments, the correct definition would be functions f;. As it is now, this would be the declaration of a function taking no arguments and returning an object of type functions).



The second one here:



for(int f = 1; f<4; f++){


is of type int.



The for loop is in a different scope than the where the first declaration is (each {} introduces a new scope) and therefore it is allowed to reuse identifiers for different objects.



If you refer to the doubly-used name, it will be looked up by certain rules and in the most common case the one in the most-inner scope will be used. Therefore here



cout << f.modu18()(y); //returns 0 or 1 from func


f is the loop counter of type int, not the f declare in the outer scope.



Use different variable names to solve this issue.



Additional stuff unrelated to error message:




  1. Your function modu18 is supposed to return a string, but all your return statements return integer literals which are of integer type and can not be automatically cast to std::string, or rather the implicit conversion will not do what you expect it to.


  2. You do not need classes to use multiple files. In a header file you can declare a free function with string modu18(int); and then define it in the implementation file with string modu18(int a) { ... }.


  3. Using using namespace std; is not good practice, as it will lead to very hard to understand errors down the line. Especially in header files it should never be used. Instead specify all names from the standard library fully with std::.







share|improve this answer


























  • o snap. that was major dumb. thanks for the assist!

    – Kenzi Marcel
    Nov 16 '18 at 23:04






  • 1





    @KenziMarcel The first f is actually a function, not a "variable". See stackoverflow.com/questions/180172/….

    – juanchopanza
    Nov 16 '18 at 23:05











  • @juanchopanza Yes thanks for noticing. I keep missing that for some reason.

    – user10605163
    Nov 16 '18 at 23:15












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346437%2frequest-for-member-modu18-in-f-which-is-of-non-class-type-int%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














In your function main there are two different f:



First one here



functions f();


is a variable of type functions or at least that is what you expect (see comments, the correct definition would be functions f;. As it is now, this would be the declaration of a function taking no arguments and returning an object of type functions).



The second one here:



for(int f = 1; f<4; f++){


is of type int.



The for loop is in a different scope than the where the first declaration is (each {} introduces a new scope) and therefore it is allowed to reuse identifiers for different objects.



If you refer to the doubly-used name, it will be looked up by certain rules and in the most common case the one in the most-inner scope will be used. Therefore here



cout << f.modu18()(y); //returns 0 or 1 from func


f is the loop counter of type int, not the f declare in the outer scope.



Use different variable names to solve this issue.



Additional stuff unrelated to error message:




  1. Your function modu18 is supposed to return a string, but all your return statements return integer literals which are of integer type and can not be automatically cast to std::string, or rather the implicit conversion will not do what you expect it to.


  2. You do not need classes to use multiple files. In a header file you can declare a free function with string modu18(int); and then define it in the implementation file with string modu18(int a) { ... }.


  3. Using using namespace std; is not good practice, as it will lead to very hard to understand errors down the line. Especially in header files it should never be used. Instead specify all names from the standard library fully with std::.







share|improve this answer


























  • o snap. that was major dumb. thanks for the assist!

    – Kenzi Marcel
    Nov 16 '18 at 23:04






  • 1





    @KenziMarcel The first f is actually a function, not a "variable". See stackoverflow.com/questions/180172/….

    – juanchopanza
    Nov 16 '18 at 23:05











  • @juanchopanza Yes thanks for noticing. I keep missing that for some reason.

    – user10605163
    Nov 16 '18 at 23:15
















0














In your function main there are two different f:



First one here



functions f();


is a variable of type functions or at least that is what you expect (see comments, the correct definition would be functions f;. As it is now, this would be the declaration of a function taking no arguments and returning an object of type functions).



The second one here:



for(int f = 1; f<4; f++){


is of type int.



The for loop is in a different scope than the where the first declaration is (each {} introduces a new scope) and therefore it is allowed to reuse identifiers for different objects.



If you refer to the doubly-used name, it will be looked up by certain rules and in the most common case the one in the most-inner scope will be used. Therefore here



cout << f.modu18()(y); //returns 0 or 1 from func


f is the loop counter of type int, not the f declare in the outer scope.



Use different variable names to solve this issue.



Additional stuff unrelated to error message:




  1. Your function modu18 is supposed to return a string, but all your return statements return integer literals which are of integer type and can not be automatically cast to std::string, or rather the implicit conversion will not do what you expect it to.


  2. You do not need classes to use multiple files. In a header file you can declare a free function with string modu18(int); and then define it in the implementation file with string modu18(int a) { ... }.


  3. Using using namespace std; is not good practice, as it will lead to very hard to understand errors down the line. Especially in header files it should never be used. Instead specify all names from the standard library fully with std::.







share|improve this answer


























  • o snap. that was major dumb. thanks for the assist!

    – Kenzi Marcel
    Nov 16 '18 at 23:04






  • 1





    @KenziMarcel The first f is actually a function, not a "variable". See stackoverflow.com/questions/180172/….

    – juanchopanza
    Nov 16 '18 at 23:05











  • @juanchopanza Yes thanks for noticing. I keep missing that for some reason.

    – user10605163
    Nov 16 '18 at 23:15














0












0








0







In your function main there are two different f:



First one here



functions f();


is a variable of type functions or at least that is what you expect (see comments, the correct definition would be functions f;. As it is now, this would be the declaration of a function taking no arguments and returning an object of type functions).



The second one here:



for(int f = 1; f<4; f++){


is of type int.



The for loop is in a different scope than the where the first declaration is (each {} introduces a new scope) and therefore it is allowed to reuse identifiers for different objects.



If you refer to the doubly-used name, it will be looked up by certain rules and in the most common case the one in the most-inner scope will be used. Therefore here



cout << f.modu18()(y); //returns 0 or 1 from func


f is the loop counter of type int, not the f declare in the outer scope.



Use different variable names to solve this issue.



Additional stuff unrelated to error message:




  1. Your function modu18 is supposed to return a string, but all your return statements return integer literals which are of integer type and can not be automatically cast to std::string, or rather the implicit conversion will not do what you expect it to.


  2. You do not need classes to use multiple files. In a header file you can declare a free function with string modu18(int); and then define it in the implementation file with string modu18(int a) { ... }.


  3. Using using namespace std; is not good practice, as it will lead to very hard to understand errors down the line. Especially in header files it should never be used. Instead specify all names from the standard library fully with std::.







share|improve this answer















In your function main there are two different f:



First one here



functions f();


is a variable of type functions or at least that is what you expect (see comments, the correct definition would be functions f;. As it is now, this would be the declaration of a function taking no arguments and returning an object of type functions).



The second one here:



for(int f = 1; f<4; f++){


is of type int.



The for loop is in a different scope than the where the first declaration is (each {} introduces a new scope) and therefore it is allowed to reuse identifiers for different objects.



If you refer to the doubly-used name, it will be looked up by certain rules and in the most common case the one in the most-inner scope will be used. Therefore here



cout << f.modu18()(y); //returns 0 or 1 from func


f is the loop counter of type int, not the f declare in the outer scope.



Use different variable names to solve this issue.



Additional stuff unrelated to error message:




  1. Your function modu18 is supposed to return a string, but all your return statements return integer literals which are of integer type and can not be automatically cast to std::string, or rather the implicit conversion will not do what you expect it to.


  2. You do not need classes to use multiple files. In a header file you can declare a free function with string modu18(int); and then define it in the implementation file with string modu18(int a) { ... }.


  3. Using using namespace std; is not good practice, as it will lead to very hard to understand errors down the line. Especially in header files it should never be used. Instead specify all names from the standard library fully with std::.








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 23:20

























answered Nov 16 '18 at 23:02









user10605163user10605163

2,868624




2,868624













  • o snap. that was major dumb. thanks for the assist!

    – Kenzi Marcel
    Nov 16 '18 at 23:04






  • 1





    @KenziMarcel The first f is actually a function, not a "variable". See stackoverflow.com/questions/180172/….

    – juanchopanza
    Nov 16 '18 at 23:05











  • @juanchopanza Yes thanks for noticing. I keep missing that for some reason.

    – user10605163
    Nov 16 '18 at 23:15



















  • o snap. that was major dumb. thanks for the assist!

    – Kenzi Marcel
    Nov 16 '18 at 23:04






  • 1





    @KenziMarcel The first f is actually a function, not a "variable". See stackoverflow.com/questions/180172/….

    – juanchopanza
    Nov 16 '18 at 23:05











  • @juanchopanza Yes thanks for noticing. I keep missing that for some reason.

    – user10605163
    Nov 16 '18 at 23:15

















o snap. that was major dumb. thanks for the assist!

– Kenzi Marcel
Nov 16 '18 at 23:04





o snap. that was major dumb. thanks for the assist!

– Kenzi Marcel
Nov 16 '18 at 23:04




1




1





@KenziMarcel The first f is actually a function, not a "variable". See stackoverflow.com/questions/180172/….

– juanchopanza
Nov 16 '18 at 23:05





@KenziMarcel The first f is actually a function, not a "variable". See stackoverflow.com/questions/180172/….

– juanchopanza
Nov 16 '18 at 23:05













@juanchopanza Yes thanks for noticing. I keep missing that for some reason.

– user10605163
Nov 16 '18 at 23:15





@juanchopanza Yes thanks for noticing. I keep missing that for some reason.

– user10605163
Nov 16 '18 at 23:15




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346437%2frequest-for-member-modu18-in-f-which-is-of-non-class-type-int%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly