Error C2533 Constructors Not Allowed A Return
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about error c2533: '::{ctor}' : constructors not allowed a return type hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Why Return Type Is Not Allowed For Constructor In Java
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Ctor not allowed return type up vote 33 down vote favorite Having code: struct B { int* a; B(int value):a(new int(value)) { } B():a(nullptr){} B(const B&); } B::B(const B& pattern) { } I'm getting err msg: 'Error 1 error C2533: 'B::{ctor}' : constructors not allowed a return type' Any idea why? P.S. I'm using VS 2010RC c++ constructor share|improve this question asked Apr 5 '10 at 16:57 There is nothing we can do 7,6351267138 22 ah, the dreaded semi-colon at end of struct/class. –falstro Apr 5 '10 at 17:00 add a comment| 2 Answers 2 active oldest votes up vote 58 down vote accepted You're missing a semicolon after your struct definition. The error is correct, constructors have no return type. Because you're missing a semicolon, that entire struct definition is seen as a return type for a function, as in: // vvv return type vvv struct { /* stuff */ } foo(void) { } Add your semicolon: struct B { int* a; B(int value):a(new int(value)) { } B():a(nullptr){} B(const B&); }; // end class definition // ah, no return type B::B(const B& pattern) { } share|improve this answer answered Apr 5 '10 at 16:58 GManNickG 231k29346470 Thanks. BTW does anyone knows in c++0x there won't be need for that silly semicolon? When you think about this it's somewhat incosistent with other constructs in c++. Or am I missing something? –There is nothing we can do Apr 5 '10 at 17:00 It's kind of a c hangover, the declaration of a struct is the definition of a type, and the declaration of a class looks like a struct. ps VS2010 warns you about this! –Martin Beckett Apr 5 '10 at 17:03 10 @Martin: it's not just a "hangover" from C. Something like: class { /* ...*/ } object; is allowed, so the semicolon is needed to tell the compiler it's reached the end of the class definition. –Jerry Coffin Apr 5 '10 at 17:08 add a comment| up vote 10 down vote You need a better c
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join http://stackoverflow.com/questions/2579657/ctor-not-allowed-return-type them; it only takes a minute: Sign up Error C2533: Constructors not allowed a return type up vote 0 down vote favorite Why does it show an error? and why can't I use a return type? This is the part of the code where the error exists template
send that format.Compiler http://www.cplusplus.com/forum/beginner/7377/ gives an error like that : error C2533: http://forums.devarticles.com/c-c-help-52/constructors-not-allowed-a-return-type-compile-error-please-help-75981.html '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
Forums >Programming >C/C++ Help "constructors not allowed a return type" compile error, please help Discuss "constructors not allowed a return type" compile error, please help in the C/C++ Help forum on Dev Articles. "constructors not allowed a return type" compile error, please help C/C++ Help forum discussing building and maintaining applications in C/C++. Find out why these languages are the foundation on which other languages are built. Add This Thread To: Del.icio.us Digg Google Spurl Blink Furl Simpy Y! MyWeb « Previous Thread | Next Thread » Thread Tools Search this Thread Display Modes Dev Articles Community Forums Sponsor: #1 October 18th, 2006, 08:54 PM cards1007 Registered User Join Date: Oct 2006 Posts: 2 Time spent in forums: 44 m 8 sec Reputation Power: 0 "constructors not allowed a return type" compile error, please help I'm just getting started programming, and I'm using the book "C++: How To Program 5th Edition". I'm trying to complete one of the exercises (Chapter 3, exercise 3.13 for those that have the book...) and I'm having one compile error I can't seem to figure out. I have the program broken up into three files, Invoice.h is the class definition, Invoice.cpp defines the member functions, and Invoice Exercise.cpp will contain the main function to create the objects and call their functions to display information. Invoice.h compiles correctly and contains the following: Code: // Chapter 3 Exercise 3.13: Invoice class // This file presents the Invoice class definition. #include