473,796 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error: member function redeclaration not allowed

2 New Member
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::print Socket(void)' : member function redeclaration not allowed

Any help would be awsome!
Feb 8 '07 #1
3 13480
nickyeng
254 Contributor
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
silentcoast
2 New Member
ok I took it out now i get

visual studio 2005\projects\a umudin2\aumudin 2\network.cpp(2 5) : error C2761: 'void CNetwork::print Socket(void)' : member function redeclaration not allowed

visual studio 2005\projects\a umudin2\aumudin 2\network.cpp(2 6) : error C2447: '{' : missing function header (old-style formal list?)
Feb 9 '07 #3
horace1
1,510 Recognized Expert Top Contributor
ok I took it out now i get

visual studio 2005\projects\a umudin2\aumudin 2\network.cpp(2 5) : error C2761: 'void CNetwork::print Socket(void)' : member function redeclaration not allowed

visual studio 2005\projects\a umudin2\aumudin 2\network.cpp(2 6) : 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
9377
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, func);
2
3640
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 support. (first i compiled them with g++3.x. ERR means compiler will bark, otherwise it does accept it. Then the Comeau C/C++ 4.3.3 comes)
13
3276
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
8257
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 solution? Declaring the function extern "C" fails, because linkage declarations must be made at file scope. #include <stdlib.h> //for qsort template <class T> class Sorter
11
11058
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
21361
by: Simon | last post by:
Hi, I have something like // // common.h const unsigned long m_dwStyle = 0x123; // // common.h
2
1616
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 a course name and instructor name GradeBook gradeBook( "CS101 Introduction to C++ Programming" );
10
4120
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 allowed to access the protected data members of the base object. This surprises me. Can someone explain why this is? I suspect there is a good reason and I am just having a slow day to not come up with it myself. Bob
2
6172
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 the .h file #pragma once #ifndef TREENODE_H #define TREENODE_H #include <iostream> #include <string>
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9525
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.