Constructors Not Allowed A Return Type Error
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
Error C2533 ' Ctor ' Constructors Not Allowed A Return Type
site About Us Learn more about Stack Overflow the company Business Learn more constructors not allowed a return type visual c++ about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x why return type is not allowed for constructor in java 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
C++ Destructor
allowed return type up vote 34 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,6171267137 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 231k29346469 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
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 http://stackoverflow.com/questions/2579657/ctor-not-allowed-return-type 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 C++ compilation error, constructor has no return type… but I didn't specify one up vote 2 down vote favorite So here is the error: 1>c:\users\ben\documents\visual studio 2010\projects\opengl_learning\opengl_learning_without_glut\openglcontext.cpp(18): http://stackoverflow.com/questions/5702342/c-compilation-error-constructor-has-no-return-type-but-i-didnt-specify-on error C2533: 'OpenGLContext::{ctor}' : constructors not allowed a return type And here is a block of code where the error points, specifically the error originates from the default constructor: #include
Visual Studio Languages , Windows Desktop Development > C++ Standards, Extensions, and Interop Question 0 Sign in to vote I'm working on an RTS game and https://social.msdn.microsoft.com/Forums/vstudio/en-US/71455a67-8892-461f-b732-8f17862b1e37/buildorderctor-constructors-not-allowed-a-return-type?forum=vclanguage at the moment I'm developing a build order system. When I try and compile I get this error: error C2533: 'BUILDORDER::{ctor}' : constructors not allowed a return type This occurs at: Code Snippet BUILDORDER::BUILDORDER(){ chainobject chainobj; chainobj.type = 0; chainobj.numberof = 0; chainobj.on = false;
for(int i = 0; i <= (MAX_CHAIN - 1); not allowed i++){ chain.push_back(&chainobj); } } I defined this constructor like this: Code SnippetBUILDORDER(); And that was as a public item. I don't have a clue why this error is occuring. Please help me find the problem quickly so I can get on with the next part of the build order system, the graphical part. Thanks in constructors not allowed advance. Thursday, May 17, 2007 8:29 AM Reply | Quote Answers 0 Sign in to vote I think it can be caused by a missing semicolon. Add it after "}" at the end of class declaration: Code Snippet class BUILDORDER { BUILDORDER(); }; // ";" must be here BUILDORDER::BUILDORDER() { } I hope this helps. Otherwise see what else you have before BUILDORDER::BUILDORDER. Thursday, May 17, 2007 8:41 AM Reply | Quote All replies 0 Sign in to vote I think it can be caused by a missing semicolon. Add it after "}" at the end of class declaration: Code Snippet class BUILDORDER { BUILDORDER(); }; // ";" must be here BUILDORDER::BUILDORDER() { } I hope this helps. Otherwise see what else you have before BUILDORDER::BUILDORDER. Thursday, May 17, 2007 8:41 AM Reply | Quote 0 Sign in to vote I had left out the ; thanks for the help. Thursday, May 17, 2007 9:51 AM Reply | Quote Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the