473,388 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Error: member function redeclaration not allowed

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
  1. #include "main.h"
  2.  
  3. CNetwork net;
  4.  
  5. int main()
  6. {
  7.     int on = 0;
  8.     int command;
  9.  
  10.     while(on == 0)
  11.     {
  12.         printf("press 1 to connect to network, 2 to display socket,3 to exit.");
  13.         cin >> command;
  14.         if(command == 1)
  15.         {
  16.             net.startupClient();
  17.         }//end if startupclient
  18.         if(command == 2)
  19.         {
  20.             net.printSocket(); 
  21.         }//end if printsocket
  22.         else
  23.         {
  24.             on = 1;
  25.         }//end else
  26.     }//end while on
  27.     return 0;
  28. }//end main
MAIN.H
Expand|Select|Wrap|Line Numbers
  1. #ifndef _MAIN_H
  2. #define _MAIN_H
  3. //defines
  4. #define _CRT_SECURE_NO_DEPRECATE
  5. //includes
  6. #include <iostream>
  7. #include <winsock2.h>
  8. #include <stdio.h>
  9. #include "network.h"
  10. //librarys
  11. #pragma comment(lib, "ws2_32.lib")
  12. //declare
  13.  
  14. //namespaces
  15. using std::cout;
  16. using std::endl;
  17. using std::cin;
  18.  
  19. #endif
  20.  
network.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef _NETWORK_H
  2. #define _NETWORK_H
  3. #include "main.h"
  4.  
  5. class CNetwork
  6. {
  7. public:
  8.     void startupClient();
  9.     void printSocket();
  10. private:
  11.     void shutdownClient(int *mySocket);
  12.     int *mySocket;
  13. };
  14.  
  15. #endif
  16.  
network.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "main.h"
  2.  
  3. void CNetwork::startupClient() 
  4. {
  5.     int error;
  6.     WSAData wsaData;
  7.     error = WSAStartup(MAKEWORD(2,2), &wsaData);
  8.     if(error == SOCKET_ERROR)
  9.     {
  10.         printf("Could Not Start Up WinSock!\n");
  11.     }
  12.     printf("WinSocket started\n");
  13.     int mySocket;
  14.     mySocket = socket(AF_INET, SOCK_STREAM, 0);
  15.     &mySocket;
  16.     if(mySocket == SOCKET_ERROR)
  17.     {
  18.         printf("Error Opening Socket!\n");
  19.     }
  20.     printf("Socket Opened!\n");
  21.     //shutdownClient(&mySocket); //DEBUG ONLY
  22.  
  23. }//end startnetwork
  24.  
  25. void CNetwork::printSocket();
  26. {
  27.     printf(*mySocket);
  28. }//end printsocket
  29.  
  30. void CNetwork::shutdownClient(int *mySocket)
  31. {
  32.     printf("Closing Socket: %i\n", *mySocket);
  33.     closesocket(*mySocket);
  34.     printf("Socket Closed\n");
  35. }//end shutdownnetwork
  36.  
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
3 13429
nickyeng
254 100+
Hi there.

the solution is, syntaz error in your network.cpp
Expand|Select|Wrap|Line Numbers
  1. .....
  2. ......
  3. void CNetwork::printSocket()
  4. {
  5.     printf(*mySocket);
  6. }//end printsocket
  7. ......
  8. ......
  9.  
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
ok I took it out now i get

visual studio 2005\projects\aumudin2\aumudin2\network.cpp(25) : error C2761: 'void CNetwork::printSocket(void)' : member function redeclaration not allowed

visual studio 2005\projects\aumudin2\aumudin2\network.cpp(26) : error C2447: '{' : missing function header (old-style formal list?)
Feb 9 '07 #3
horace1
1,510 Expert 1GB
ok I took it out now i get

visual studio 2005\projects\aumudin2\aumudin2\network.cpp(25) : error C2761: 'void CNetwork::printSocket(void)' : member function redeclaration not allowed

visual studio 2005\projects\aumudin2\aumudin2\network.cpp(26) : error C2447: '{' : missing function header (old-style formal list?)
after I fixed the missing ; problem identified by nickyeng I got an error indicating a missing conversion specification in the printf call in printSocket(). I fixed it so
Expand|Select|Wrap|Line Numbers
  1. void CNetwork::printSocket()
  2. {
  3.     printf("*mySocket\n",  *mySocket);  //*** ????
  4. }//end printsocket
  5.  
it now compiles OK
Feb 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1,...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
13
by: MJ | last post by:
Hi I have a basic doubt about structure. I have a class in which a I have declared a static funtion class A { public: static a; static f(); };
9
by: tropostropos | last post by:
On Solaris, using the Sun compiler, I get annoying warnings from the following code. The problem is that I am passing a C++ member function pointer to the C library function qsort. Is there a...
11
by: Marco Wedekind | last post by:
Hello all, I have a strange compiler behaviour with this code: ---- Begin of code snippet ---- class Base { public: static unsigned int ClassId();
10
by: Simon | last post by:
Hi, I have something like // // common.h const unsigned long m_dwStyle = 0x123; // // common.h
2
by: adrix7 | last post by:
hi, been having error "member function error" i really dont know what to do, please help. I've typed the error in Bold.. thanks guys/gals! int yes1; // create a GradeBook object; pass...
10
by: blangela | last post by:
If I pass a base class object by reference (likely does not make a difference here that it is passed by reference) as a parameter to a derived class member function, the member function is not...
2
by: addison5390 | last post by:
So, below is code for a binary tree, the structure is referred to as TreeNode. I'm having some trouble separating what information goes into the TreeNode.h file and the TreeNode.cpp file. Here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.