How do I create a custom class in Visual Studio?

I am writing a program to generate cells using Wolfram’s rule. It is called Cellular Automata, But I call it ca for short in the program. I have made a function called void ofApp :: cells (float ca) and then I have written ca.push_back.display(); but it says ‘Expression must have a class type’ can someone please tell me what this means and give an example? Lastly I should mention that ca is in written like this in the header filevector <float> ca;

Thanks,

Jade

Hey Jade,

You should check how to use vectors in your code. I recommend you to take a look the following link;
http://openframeworks.cc/ofBook/chapters/stl_vector.html

If you initialise ca in your .h file;
vector<float> ca;

then you can pushback values like following in your .cpp file;
ca.push_back(0.01);
ca.push_back(0.04);
.
.
.
and so on

Hi alp,

I have added pushback values and it is still giving me an error. I am totally lost on why this is happening too and I have read the vector guide before. Am I doing something else wrong? It is still saying that the expression must have a class type. Do i need to create a custom class called ‘ca’, and if so how would I do this?

It can be caused by couple of reasons. Can you paste your ofApp.h and ofApp.cpp codes here? If we can see your complete code, it’s easier to fix your issues and suggest you what to do

#include "ofApp.h"


//--------------------------------------------------------------
void ofApp::setup(){
	ruleset = { 0, 1, 1, 1, 0, 0, 1, 0 }; //this is the initial ruleset
	ca = (ruleset); // cellular automata will follow the ruleset
	ofSetFrameRate(30); //framerate at 30 FPS
	ofSetBackgroundAuto(255); // set to white
}

//--------------------------------------------------------------
void ofApp::update(){
	
}

//--------------------------------------------------------------
void ofApp::draw(){
	cells(0.2);
}

void ofApp::cells(int i) {

	ca.push_back(0.1);//push_back adds a new element to the end of the vector so i am adding 0.1 to the end of the ruleset





}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}


//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 

}
#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
		void cells (int i);

		vector <float> ruleset;
		vector <float> ca; 
		int delay;
};

Slightly modified the code, Although I am not sure I get what it means, Sorry to be a pain, i’m new to programming and this is really important as it is for an assignment and I don’t want to fail!

I want to generate cells based on Wolfram. Please help as much as you can, I would really appreciate it!

Thank you for your help so far too!

You pass floating numbers to your cells function, but you define the parameter inside cell function as int. It should be;

void cells(float i)

in your .cpp and .h files

Probably your are out of memory because of you pushback ca vector in draw function. This means ca vector size increasing continuously until your computer run out of memory. Because, draw() function runs until you stop your application.
I suggest you to pushback the values into ca in setup function. If you need to dynamically change ca’s content, it’s better to add some conditionals blocks to keep the size of your ca vector in acceptable ranges.

void ofApp::draw(){
   cells(0.2);
   if (ca.size() > 500){
     ca.erase(ca.begin());
   }
}

Take a look at the examples in openframeworks folder.

How do you mean? I’m probably not explaining myself properly. I want to basically turn the code below into Openframeworks language and change it up abit. The problem is, the syntax is different and I don’t quite understand how to translate it.

CA ca;   // An object to describe a Wolfram elementary Cellular Automata


void setup() {
  size(800, 100);
  frameRate(30);
  background(255);
  //int[] ruleset = {0,1,1,1,1,0,1,1};           // Rule 222  
  //int[] ruleset = {0,1,1,1,1,1,0,1};           // Rule 190  
  int[] ruleset = {0,1,1,1,1,0,0,0};           // Rule 30  
  //int[] ruleset = {0,1,1,1,0,1,1,0};             // Rule 110  
  
  ca = new CA(ruleset);                 // Initialize CA
}

void draw() {
  ca.display();          // Draw the CA
  ca.generate();
}