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 7093955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:30:14+00:00 2026-05-28T08:30:14+00:00

i have 2 void functions(trying to implement radio button), i want them to send

  • 0

i have 2 void functions(trying to implement radio button), i want them to send value to a third function by swapping values. and that function returning value to main function?

CODE OF MY MyScene.h FILE

#ifndef __MY_SCENE_H__
#define __MY_SCENE_H__

#include "cocos2d.h"
USING_NS_CC;

class MyScene : public cocos2d::CCLayerColor
{
public:
    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    // there's no 'id' in cpp, so we recommand to return the exactly class pointer
    static cocos2d::CCScene* scene();


    CCMenuItemToggle *R;

    CCMenuItemToggle *L;

    // a selector callback
    void swapL(CCObject *sender);
    void swapR(CCObject *sender);

    // implement the "static node()" method manually
    LAYER_NODE_FUNC(MyScene);
};

#endif // __HELLOWORLD_SCENE_H__

CODE OF MY MyScene.cpp FILE

#include "MyScene.h"

USING_NS_CC;

CCScene* MyScene::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::node();

    // 'layer' is an autorelease object
    MyScene *layer = MyScene::node();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool MyScene::init()
{


    //////////////////////////////
    // 1. super init first
    if ( !CCLayerColor::initWithColor(ccc4(255,255,255,255) ))
    {
        return false;
    }

    //////////////////////////////
    // 2. add your codes below...

    CCSize WinSize= CCDirector::sharedDirector()->getWinSizeInPixels();

    CCSprite * fish=CCSprite::spriteWithFile("fish_bg.png");
    fish->setPosition(CCPointZero);
    fish->setAnchorPoint(CCPointZero);
    fish->setScaleX(WinSize.width/480);
    fish->setScaleY(WinSize.height/395);
    this->addChild(fish,0,0);


    CCSprite * on1=CCSprite::spriteWithFile("on.png");
    CCSprite * on2=CCSprite::spriteWithFile("on.png");
    CCSprite * on3=CCSprite::spriteWithFile("on.png");
    CCSprite * on4=CCSprite::spriteWithFile("on.png");

    CCSprite * off1=CCSprite::spriteWithFile("off.png");
    CCSprite * off2=CCSprite::spriteWithFile("off.png");
    CCSprite * off3=CCSprite::spriteWithFile("off.png");
    CCSprite * off4=CCSprite::spriteWithFile("off.png");


    CCMenuItem *LeftOn=CCMenuItemSprite::itemFromNormalSprite(on1,on2);
    CCMenuItem *RightOn=CCMenuItemSprite::itemFromNormalSprite(on3,on4);
    CCMenuItem *LeftOff=CCMenuItemSprite::itemFromNormalSprite(off1,off2);
    CCMenuItem *RightOff=CCMenuItemSprite::itemFromNormalSprite(off3,off4);

    CCMenuItemToggle *Left  = CCMenuItemToggle::itemWithTarget(this, menu_selector(MyScene::swapL),LeftOn,LeftOff,NULL);

    CCMenuItemToggle *Right = CCMenuItemToggle::itemWithTarget(this, menu_selector(MyScene::swapR),RightOn,RightOff,NULL);

    CCMenu *Radio= CCMenu::menuWithItems(Left,Right,NULL);

    Radio->alignItemsHorizontallyWithPadding(20);
    Radio->setPosition(ccp(WinSize.width/2,WinSize.height/2));


    this->addChild(Radio);
    //////////////////////////////
    return true;
}

void MyScene::swapL(CCObject *sender)
{
    L= (CCMenuItemToggle*)sender;
    CCLOG("L= %d",L->getSelectedIndex());

    int i=(L->getSelectedIndex());


}

void MyScene::swapR(CCObject *sender)
{
    R= (CCMenuItemToggle*)sender;

    CCLOG("R= %d",R->getSelectedIndex());
    int j=(R->getSelectedIndex());


}
  • 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-05-28T08:30:14+00:00Added an answer on May 28, 2026 at 8:30 am

    Is it possible to have 2 void functions to send arguements to a third function one each from those 2 functions ?

    Yes, It’s possible, Why do you think it is not possible?

    Online Sample:

    #include<iostream>
    
    void doSomething(int &i)
    {
        i = 10;
    }
    
    void doSomethingMore(int &j)
    {
        j = 20;
    }
    
    void FinalDoSomething(const int i, const int j, int &k)
    {
        k = i + j;
    }
    
    int main()
    {
        int i = 0;
        doSomething(i);    
    
        int j = 0;
        doSomethingMore(j);
    
        int k = 0;
        FinalDoSomething(i,j,k);
    
        std::cout<<k;
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I am trying to implement a template function with handles void differently using template
I have this hashCode function that I have been trying to implement with Eclipse
Suppose I have two functions which look like this: public static void myFunction1(int a,
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
I have this function: void ToUpper(char * S) { while (*S!=0) { *S=(*S >=
Suppose I have this function: void my_test() { A a1 = A_factory_func(); A a2(A_factory_func());
I have: void add_all_msgs(std::deque<Message>::iterator &iter); How can I make that function generic, so it
I'm getting Reaching end of non-void function warning, but don't have anything else to

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.