Alright im not sure why but im getting a "member function redeclaration not allowed" error when I to compile this simple program.
main.cpp - #include "main.h"
-
-
CNetwork net;
-
-
int main()
-
{
-
int on = 0;
-
int command;
-
-
while(on == 0)
-
{
-
printf("press 1 to connect to network, 2 to display socket,3 to exit.");
-
cin >> command;
-
if(command == 1)
-
{
-
net.startupClient();
-
}//end if startupclient
-
if(command == 2)
-
{
-
net.printSocket();
-
}//end if printsocket
-
else
-
{
-
on = 1;
-
}//end else
-
}//end while on
-
return 0;
-
}//end main
MAIN.H - #ifndef _MAIN_H
-
#define _MAIN_H
-
//defines
-
#define _CRT_SECURE_NO_DEPRECATE
-
//includes
-
#include <iostream>
-
#include <winsock2.h>
-
#include <stdio.h>
-
#include "network.h"
-
//librarys
-
#pragma comment(lib, "ws2_32.lib")
-
//declare
-
-
//namespaces
-
using std::cout;
-
using std::endl;
-
using std::cin;
-
-
#endif
-
network.h -
#ifndef _NETWORK_H
-
#define _NETWORK_H
-
#include "main.h"
-
-
class CNetwork
-
{
-
public:
-
void startupClient();
-
void printSocket();
-
private:
-
void shutdownClient(int *mySocket);
-
int *mySocket;
-
};
-
-
#endif
-
network.cpp -
#include "main.h"
-
-
void CNetwork::startupClient()
-
{
-
int error;
-
WSAData wsaData;
-
error = WSAStartup(MAKEWORD(2,2), &wsaData);
-
if(error == SOCKET_ERROR)
-
{
-
printf("Could Not Start Up WinSock!\n");
-
}
-
printf("WinSocket started\n");
-
int mySocket;
-
mySocket = socket(AF_INET, SOCK_STREAM, 0);
-
&mySocket;
-
if(mySocket == SOCKET_ERROR)
-
{
-
printf("Error Opening Socket!\n");
-
}
-
printf("Socket Opened!\n");
-
//shutdownClient(&mySocket); //DEBUG ONLY
-
-
}//end startnetwork
-
-
void CNetwork::printSocket();
-
{
-
printf(*mySocket);
-
}//end printsocket
-
-
void CNetwork::shutdownClient(int *mySocket)
-
{
-
printf("Closing Socket: %i\n", *mySocket);
-
closesocket(*mySocket);
-
printf("Socket Closed\n");
-
}//end shutdownnetwork
-
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!
3 13480
Hi there.
the solution is, syntaz error in your network.cpp -
.....
-
......
-
void CNetwork::printSocket()
-
{
-
printf(*mySocket);
-
}//end printsocket
-
......
-
......
-
in the line printSockect function, you SHOULDNT have a " ; " in the back. delete it.
i hope i helped.
from
Nicky Eng
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?)
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 -
void CNetwork::printSocket()
-
{
-
printf("*mySocket\n", *mySocket); //*** ????
-
}//end printsocket
-
it now compiles OK
Sign in to post your reply or Sign up for a free account.
Similar topics |
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);
|
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)
|
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();
};
|
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
|
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();
| |
by: Simon |
last post by:
Hi,
I have something like
//
// common.h
const unsigned long m_dwStyle = 0x123;
//
// common.h
|
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" );
|
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
|
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>
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |