ERROR! no constructor could take.....

Hi fellow programmers. I'm current using VB C++ 6.0
I don't know what's wrong with my code. I think it's right
can you guys please explain to me what this error is??
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
#include<iostream>
#include<string>
using namespace std;

const int NUMRECS=2;

struct PayRec
{
	string name;
	int pay;
};

int main()
{
	int i;
	PayRec employee[NUMRECS]={
		{"Johnsons",200},
		{"paxons",200}
	};

	cout<<endl;
	for(i=0; i<NUMRECS; i++)
	{
		cout<<employee[i].name<<endl;
		cout<<employee[i].pay<<endl;
	}

	return 0;
}


error C2440: 'initializing' : cannot convert from 'const int' to 'struct PayRec'
No constructor could take the source type, or constructor overload resolution was ambiguous












































closed account (S6k9GNh0)
If you really are using Visual Studio 6.0, I would HIGHIGHLHGOIHLGHIHGLY recommend moving to a new version or to a more modern compiler.
Last edited on
VB C++ 6.0


Visual Basic C++ 6.0? I hope you mean Visual Studio 6 (which, by the way, has a C++ compiler containing a number of know bugs and other issues - why not upgrade to something better and free of charge?)

Anyway, your code compiles and runs on two of my systems, and also here: http://ideone.com/lxnXv





I think it's only my version that's making the problem. Thank you guys for helping.
VC++6 is defunct - get rid of it.



By the way this would be a solution using VC++6
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
#include<iostream>
#include<string>
using namespace std;

const int NUMRECS=2;

struct PayRec
{
    string name;
    int pay;
    
    PayRec(string _name, int _pay) 
    {

        name = _name;
        pay = _pay;
    };
    
};

int main()
{
    int i;
    PayRec employee [NUMRECS]={ { PayRec("Johnsons",200) },{ PayRec("paxons",200) } };


    
    cout<<endl;
    for(i=0; i<NUMRECS; i++)
    {
        cout<<employee[i].name<<endl;
        cout<<employee[i].pay<<endl;
    }

    return 0;
}
Topic archived. No new replies allowed.