error C3861: 'stuff': identifier not found

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
//.h file code:

#include <string>
#include <iostream>

class One
	{
	public:
		void showone();
	};
	class Two : public One
	{
	public:
		void showtwo();
	};
	class Program
	{
		static void Main(std::string args[]);
	public:
		static void stuff(One *o);
	};

//.cpp file code:

void One::showone()
{
std::cout << "One" << std::endl;
}

void Two::showtwo()
{
	std::cout << "Two" << std::endl;
}

static void main()
{
	One *uno = new Two();
	Two *dos = new Two();
	stuff(uno);//error C3861: 'stuff': identifier not found
	stuff(dos);//error C3861: 'stuff': identifier not found
}

static void stuff(One *o)
{
	o->showone();
}


How do I pass the objects to this method?
Try putting the function above main ;-)...

Or declaring it before main at least...
thank you attaboy here is the code
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
//.h file code:

#include <string>
#include <iostream>

class One
	{
	public:
		void showone();
	};
	class Two : public One
	{
	public:
		void showtwo();
		
	};
	
//.cpp file code:

void One::showone()
{
std::cout << "One" << std::endl;
}

void Two::showtwo()
{
	std::cout << "Two" << std::endl;
}
	void stuff(One *o)
{
	o->showone();
}
static void main()
{
	One *uno = new Two();
	Two *dos = new Two();
	stuff(uno);
	stuff(dos);
	
}
Output:
One
One
Press any key to continue . . .
main() should not be static and returns an int.

1
2
3
4
int main()
{
return 0;
}


You're also creating a memory leak on lines 35 & 36.

Any memory you allocate with new must be released by an associated delete

1
2
3
4
5
One *uno = new Two();
Two *dos = new Two();
...
delete uno;
delete dos;


Are you getting the output you expect?
Last edited on
Topic archived. No new replies allowed.