473,395 Members | 2,467 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,395 software developers and data experts.

Problem with own class

12
I have the next piece of code:

Expand|Select|Wrap|Line Numbers
  1. vector<ChatSession> ssid;
  2.  
  3. void SessionCreator( void *ch ) 
  4. {
  5.     vector<string> users;
  6.  
  7.        ...
  8.        ...
  9.        ...
  10.  
  11.     ChatSession cs;
  12.  
  13.     // put chat session objects in vector array
  14.     for (int i = 0; i < (int)users.size(); i++)
  15.     {
  16.         const char *t = users[i].data();
  17.         char t2[30]; memcpy(t2, t, strlen(t));
  18.         cs = new ChatSession(*t2);
  19.         ssid.push_back(cs);
  20.     }
  21.  
  22.     // Terminate myself
  23.     _endthread();
  24. }
program.h:
Expand|Select|Wrap|Line Numbers
  1. class ChatSession
  2.     {
  3.     private:
  4.         char ChatID[100];
  5.         char Name[30];
  6.         char Message[1024];
  7.         char newMsg[1024];
  8.         bool CanSend;
  9.     public:
  10.         ChatSession();
  11.         ChatSession(char *nickname);
  12.         ~ChatSession();
  13.         void SetChatID(char* id);
  14.         void Send();
  15.         char *getName();
  16.         bool ready();
  17.     };
  18.     ...
  19.     ...
  20.     ...
  21.  
  22. extern vector<ChatSession> ssid;
  23.  
VC++ throws angry error error at me:
Expand|Select|Wrap|Line Numbers
  1. Line: cs = new ChatSession(*t2);
Expand|Select|Wrap|Line Numbers
  1. Error C2664: 'ChatSession::ChatSession(char *)' : cannot convert parameter 1 from 'char' to 'char *'


Please help.
Jul 21 '09 #1
3 1581
Banfa
9,065 Expert Mod 8TB
remove the * in *t2, you are deferencing the pointer.

Also where you populate the array t2 you have made some mistakes.

You call data but that returns an array wthout a zero terminator so you can not call strlen on it. If you want the zero terminator copied then call string::c_str instead of string::data but remeber strlen returns the number of characters in the string excluding the zero terminator. If you don't want the terminator then string::size returns the number of characters in the string.
Jul 21 '09 #2
mcco
12
I modified my code to use char pointer vector, but this still doesn't work.. it gives another error now:

Expand|Select|Wrap|Line Numbers
  1. void SessionCreator( void *ch ) 
  2. {
  3.     vector<char *> users;
  4.  
  5.     // Split the string
  6.     Split((char *)ch, ", ", users);
  7.  
  8.     ChatSession cs;
  9.  
  10.     // Initialize the ssesions array with each user
  11.     for (int i = 0; i < (int)users.size(); i++)
  12.     {
  13.         cs = new ChatSession(users[i]);
  14.         ssid.push_back(cs);
  15.     }
  16.  
  17.     // Terminate myself
  18.     _endthread();
  19. }
Expand|Select|Wrap|Line Numbers
  1. Line: cs = new ChatSession(users[i]);
Expand|Select|Wrap|Line Numbers
  1. error C2679: binary '=' : no operator found which takes a right-hand operand of type 'ChatSession *' (or there is no acceptable conversion)

@Banfa
Removing the pointer sign gives me the same error as above,
but thanks for telling me about strlen() else i would leave it in numerous places like that and it'd keep me puzzled :D
Jul 21 '09 #3
Banfa
9,065 Expert Mod 8TB
@mcco
cs is an object (of type ChatSession), new ChatSession(users[i]) has type ChatSession *

Perhaps cs should be a pointer?
Jul 21 '09 #4

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

Similar topics

1
by: delerious | last post by:
Could someone please take a look at this page: http://home.comcast.net/~delerious1/index11.html The set of links on the left should not have any whitespace between them, and the set of links...
3
by: Omer van Kloeten | last post by:
The Top Level Design: The class Base is a factory class with a twist. It uses the Assembly/Type classes to extract all types that inherit from it and add them to the list of types that inherit...
6
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
6
by: Nafai | last post by:
Hello. I want to do something like this: class A { // It's virtual protected: float* data; int n; public: A(int a); virtual float* createData(); //...
2
by: Bonj | last post by:
Hello Can anyone assist with the following class hierarcy problem? I have a series of window classes, the object model currently being as such: Window / | \ / | \...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
5
by: Tio | last post by:
I have project in MFC(vc++) . There are files and classes: classes:dialog1,dialog2,aaa,bbb ---------------------- main.cpp --------------------- #include "mainfrm.h" #include "dialog1.h"...
2
by: Ravi Joshi | last post by:
The menu on my site works fine in IE6 and Firefox. In IE7, there is a problem with the menu: when you mouse over the various main catagories, the sub-catagories all appear to the right as they...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.