Passing struct type params?

hi,
I have a class class A and it has void mymethod(pay m) and i am in class B I want to pass m parameter to the mymethod in the class A. The pay is a struct declared class B.so when i try to pass the m parameter to the mymethod. it says no matching function for call to A::mymethod(m). any idea? do not worry about the pay struct it is defined in class B. mymethod is public. and in different .cc file and declared in .h file.
1
2
3
4
5
6

class B{
A::mymethod(m);	

}
Last edited on
That's quite difficult to understand. Can you try to explain the problem again please. Posting your actual classes, pay struct and functions might help.
Sorry let me rewrite it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

     struct someS 
{ 
int age; 
char name[32]; 
}; //this is my struct 
//and this is my method signature. the method is in a different mClass.cc 
void mClass::myMethod(someS s) 

// in my main.cc and im passing it like this 
someS t; 
mClass m; 
m.myMethod(t); 
//here it says no matching function call to mClass::myMethod(Somes&); 
//candidates are mClass::myMethod(Somes*); 
// i tried with pointer and reference still did not work out. any idea?

Well, that's a lot of fragments, it isn't something anyone can compile to reproduce the problem.

Perhaps something like this is what you have? it compiles with an 'unused parameter' warning, but no errors.

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
struct someS 
{ 
    int age; 
    char name[32]; 
}; 

struct mClass 
{
    void myMethod(someS s); 
    
};  

void mClass::myMethod(someS s)
{
    // do something with s here    
} 

int main () 
{
    someS t; 
    mClass m; 
    m.myMethod(t);
	
    return 0;
}
Chances are you have not made something important visible to the piece of program that needs it.

Remember, outside of the current .cc file, the compiler knows absolutely nothing. That's what prototypes and the like are all about, and the word "dependencies".

1
2
3
4
5
6
7
8
9
10
11
// foo.hpp"

#ifndef FOO_HPP
#define FOO_HPP

struct someS
{
  ...
};

#endif 
1
2
3
4
5
6
7
8
9
10
11
12
13
// bar.hpp

#ifndef BAR_HPP
#define BAR_HPP

#include "foo.hpp"

struct mClass
{
  void myMethod( someS t );
};

#endif 
1
2
3
4
5
6
7
8
9
// bar.cc

#include "foo.hpp"
#include "bar.hpp"

void mClass::myMethod( someS t )
{
  ...
}
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
...

#include "foo.hpp"
#include "bar.hpp"

int main()
{
  someS t;
  mClass m;
  m.myMethod( t );
  ...

Notice how everything must not only exist, but must be declared as existing, in full, before it can be used?

Hope this helps.
Topic archived. No new replies allowed.