object pointer problem

hi why won't this work?
i'm able to make object but not object2
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
#include <iostream>
#include <stdio.h>
#include "../header_files/ob.h"


Ob::Ob()
	{
		name = "KEVIN";
		cout << "test\a";
	};
void Ob::getname()
{
	cout << name;
}

int main(int argcs,char* pArgs[])
{
	Ob* object = new Ob();
	object->getname();
	
	Ob object2(),*pob; 
	pob = &object2;
	
	
}
In general: If a constructor does not take any arguments, do not use brackets.

Specifically though, what is your problem in this case?
closed account (zb0S216C)
olifant wrote:
hi why won't this work? (sic)

That's what error messages are for. Now that you've asked, what are the errors (if any)?

olifant wrote:
Ob object2() (sic)

Hanst has already pointed this out, but I'll go a little deep. This declaration is a function prototype declaration. This is fine. However, a function prototype declaration within another function isn't allowed. My guess is that this declaration wasn't intended to be a function prototype, but an instantiation of Ob that calls the default constructor. If this is the case, follow Hanst's advice.

Wazzak
Last edited on
hi,

the error message was
"ob.cpp:22:9: error: cannot convert ‘Ob (*)()’ to ‘Ob*’ in assignment"

but leaving out the brackets solved the problem
thanks
Topic archived. No new replies allowed.