Error 1 Error C2761 Member Function Redeclaration Not Allowed
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 member function may not be redeclared outside its class Us Learn more about Stack Overflow the company Business Learn more about hiring invalid redeclaration of member function swift 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 them; it only takes a minute: Sign up Member function redeclaration not allowed up vote 1 down vote favorite If I define the function in mainwindow.cpp the function works, but when I define it in radiobuttons.cpp, and attempt to call it from mainwindow.cpp, the project won't compile. mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); void build_radios(); //this function ~MainWindow(); }; #endif // MAINWINDOW_H radiobuttons.cpp #include "mainwindow.h" #include "ui_mainwindow.h" void MainWindow::build_radios() { //... some code } mainwindow.cpp #include "mainwindow.h" #include "ui_mainwindow.h" void MainWindow::radio_buttons(); //error: C2761: 'void MainWindow::build_radios(void)' : member function redeclaration not allowed MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { radio_buttons(); } c++ compiler-errors share|improve this question edited Dec 30 '12 at 22:38 mbinette 4,13231729 asked Dec 30 '12 at 22:36 chuckieDub 49831227 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted That's not a definition, the compiler sees it as a declaration of a member function outside the class definition, which is illegal. Just remove that line. It shouldn't be there in the first place, it has no use. In fact, move the actual definition from radiobuttons.cpp to mainwindow.cpp for consistency. Why declare a MainWindow member in a different implementation file? share|improve this answer answered Dec 30 '12 at 22:38 Luchian Grigore 167k28295455 if I remove that line from mainwindow.cpp, i get :mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall MainWindow::build_radios(void)" (?build_radios@MainWindow@@QAEXXZ) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z) –chuckieDub Dec 30 '12 at 22:45 and I'm just trying to organize my code bet
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 them; it only takes a minute: Sign up Error “member function redeclaration not allowed” http://stackoverflow.com/questions/14095405/member-function-redeclaration-not-allowed with boost::thread up vote 1 down vote favorite I have this problem with boost::thread that i cannot solve. I have a classX.h file: #include class classX{ ... void startWork(void); void doWork(void); ... } and then a .cpp file: ... void classX::startWork(){ boost::thread(&doWork); } void classX::doWork(){ ... } I cannot compile, i obtein the error (at the line in which i do boost::thread(&doWork)): error C2761: 'void http://stackoverflow.com/questions/10968311/error-member-function-redeclaration-not-allowed-with-boostthread plsa_mt_2::doWork(void)' : member function redeclaration not allowed Is this error related with the thread creation or with something else? What can i do to solve it? c++ boost-thread share|improve this question asked Jun 10 '12 at 11:32 Aslan986 2,47652546 possible duplicate of Start thread with member function –George Stocker♦ Jun 10 '12 at 15:40 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted Since classX::doWork() is a member function of classX, you can't call the member function pointer (&classX::doWork) without providing a pointer to a classX. The Boostiest way to accomplish this is by using Boost Bind to create a callable functor with the member function pointer and a pointer to the classX, like so: void classX::startWork() { boost::thread t(boost::bind(&classX::doWork, this)); // be careful, the boost::thread will be destroyed when this function returns } You could alternatively make doWork() a static member function or a global function if doWork() doesn't need access to instance properties of the classX: share|improve this answer answered Jun 10 '12 at 11:56 James Brock 1,7821621 Okok I got the point. Thank you. –Aslan986 Jun 10 '12 at 11:58 add a comment|
help? Post your question and get tips & solutions from a community of 418,502 IT https://bytes.com/topic/c/answers/599368-error-member-function-redeclaration-not-allowed Pros & Developers. It's quick & easy. Error: member function redeclaration not allowed P: 2 silentcoast Alright im not sure why but im getting a "member function redeclaration not allowed" error when I to compile this simple program. main.cpp Expand|Select|Wrap|Line Numbers #include"main.h" CNetworknet; intmain() { inton=0; intcommand; while(on==0) { printf("press1toconnecttonetwork,2todisplaysocket,3toexit."); cin>>command; if(command==1) member function { net.startupClient(); }//endifstartupclient if(command==2) { net.printSocket(); }//endifprintsocket else { on=1; }//endelse }//endwhileon return0; }//endmain MAIN.H Expand|Select|Wrap|Line Numbers #ifndef_MAIN_H #define_MAIN_H //defines #define_CRT_SECURE_NO_DEPRECATE //includes #include #include #include #include"network.h" //librarys #pragmacomment(lib,"ws2_32.lib") //declare //namespaces usingstd::cout; usingstd::endl; usingstd::cin; #endif network.h Expand|Select|Wrap|Line Numbers #ifndef_NETWORK_H #define_NETWORK_H #include"main.h" classCNetwork { public: voidstartupClient(); voidprintSocket(); private: voidshutdownClient(int*mySocket); int*mySocket; }; #endif error 1 error network.cpp Expand|Select|Wrap|Line Numbers #include"main.h" voidCNetwork::startupClient() { interror; WSADatawsaData; error=WSAStartup(MAKEWORD(2,2),&wsaData); if(error==SOCKET_ERROR) { printf("CouldNotStartUpWinSock!\n"); } printf("WinSocketstarted\n"); intmySocket; mySocket=socket(AF_INET,SOCK_STREAM,0); &mySocket; if(mySocket==SOCKET_ERROR) { printf("ErrorOpeningSocket!\n"); } printf("SocketOpened!\n"); //shutdownClient(&mySocket);//DEBUGONLY }//endstartnetwork voidCNetwork::printSocket(); { printf(*mySocket); }//endprintsocket voidCNetwork::shutdownClient(int*mySocket) { printf("ClosingSocket:%i\n",*mySocket); closesocket(*mySocket); printf("SocketClosed\n"); }//endshutdownnetwork the function printSocket is wehre im having problems, if i take out that function the program runs like it is suppose to. here is the exact error... network.cpp(25) : error C2761: 'void CNetwork::printSocket(void)' : member function redeclaration not allowed Any help would be awsome! Feb 8 '07 #1 Post Reply Share this Question 3 Replies 100+ P: 254 nickyeng Hi there. the solution is, syntaz error in your network.cpp Expand|Select|Wrap|Line Numbers ..... ...... voidCNetwork::printSocket() { printf(*mySocket); }//endprintsocket ...... ...... in the line printSockect function, you SHOULDNT have a " ; " in the back. delete it. i hope i helped. from Nicky Eng Feb 8 '07 #2 reply P: 2 silentcoast ok I took it out now i get visual studio 2005\pro