Constructor return type??




Hi,
I have a problem with that code given below.This code is simplified version of my source code.Errors are same so I send that format.Compiler gives an error like that


: error C2533: 'AB::{ctor}' : constructors not allowed a return type
: error C2264: 'AB::AB' : error in function definition or declaration; function not called

But my constructor does not return any thing.




#include <iostream>
using std::cout;
using std::endl;
#include<math.h>

class AB
{
public:

AB(int=5);//constructor
void show();//print values

private:
const int size ;
int (*p);
}

AB::AB( int a )
:size(a)
{
p = new int[size];
for (int i = 0; i <= size; i++)
{
p[i] = i;
}
}
void AB::show()
{


for (int i = 0; i <= size; i++)
{
cout << p[i];

}
}

int main()
{


int x= 2;
AB ab(x);// class definition with initialization

return(0);
}
Last edited on
You missed the semicolon after your class declaration. For this reason the comiplier thinks class AB is the return type for the function AB::AB(int a)
Thanks a lot mordekai.
It worked.
Topic archived. No new replies allowed.