Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:22:46+00:00 2026-06-04T00:22:46+00:00

I am intending to initialize or create a new object using variables. The error

  • 0

I am intending to initialize or create a new object using variables.
The error says that i am conflicting declaration.

       //instantiate new node object***********************
        string peer = "peer";
        string pNo = convertInt(addPeerNum); //convert peer number to string to concatenate 2 strings
        string NewPeerObject = peer+pNo; << ERROR POINTS TO HERE
        nodes NewPeerObject; << ERROR POINTS TO HERE

Error message:

conflicting declaration ‘nodes NewPeerObject’ <– last line of error
‘NewPeerObject’ has a previous declaration as ‘string NewPeerObject’ <– 2nd last line

My main point is to create a new object when I add more peers.
If I addpeer 1, it will create a new object ‘peer1’
If I addpeer 2, it will be ‘peer2’ etc.

I am reading in the file which contains

 addpeer 1
 addpeer 100
 addpeer 28

In my program, it reads the file and stores the number in a variable called ‘addPeerNum’
and with me doing this, it actually has a different string content of ‘NewPeerObject’.

So in this instance, i am actually trying to create 3 new objects.

Is there any way which i will be able to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:22:48+00:00Added an answer on June 4, 2026 at 12:22 am

    I think that what you are looking for is a kind of dynamically resized array of your objects.
    You can use std::list to achieve that kind of behavior.

    std::list<PeerObject> list;
    PeerObject peer(peer_string);
    list.insert(peer);
    

    or a std::map if you want to use your peer string as a key

    std::map<std::string, PeerObject> peer_map;
    PeerObject peer(peer_string);
    peer_map.insert(peer_string, peer);
    //    .... add more
    PeerObject& foundObj = peer_map[a_key];
    foundObj.doSomething();
    

    You could also do it with MACROs but only at compile time and you should avoid them if possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm intending to create a flash app that pulls images from facebook and displays
I am intending to create a small api, that will do some php functions,
I'm intending to use the new .NET 4 Code Contracts feature for future development.
I am writing a translator, and have quite a few java String literals that
I was intending to create a splash screen like the one sported by Visual
This is a loop in a function intending to create elements <li> and give
I'm using a makefile intending to generate dependencies automatically. But with my file, I
I know that sometimes if you don't initialize an int , you will get
I am intending to develop a story book using cocos2d. So i think i
I am intending to implement pagination in a tableview. Currently, I am using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.