Error expression must have pointer to object type

Ответили на вопрос 1 человек. Оцените лучшие ответы! И подпишитесь на вопрос, чтобы узнавать о появлении новых ответов.

Я делаю многофайловый проект на С++ с 2 .cpp файлами и 1 .h файлом (direct.h). Вот функция main:

#include <iostream>
#include <direct.h>

using namespace std;

int direct(const int rows, const int cols, int ARR); 

int main()
{
const int rows = 9;
const int cols = 9;

int ARR[rows][cols];

direct(const int rows, const int cols, int ARR);

}

А вот моя функция, которая по спирали заполняет массив:

int direct(const int rows, const int cols, int ARR)
{
int val;

// Initialize the array to 0 values
for (int i = 0; i < rows;i++)
{
    for (int j = 0; j < cols;j++) 
    {
        val = 0;
    }
}

// Use symbols for directions
enum dir
{
    left = 0,
    down,
    up,
    right,
}
dir = left;

// Define the starting point and starting value
int x = rows / 2;
int y = cols / 2;
int val = 1;

// A flag to know when to stop
bool stop = false;

// Start
for (;;)
{
    ARR[x][y] = val++;
    switch (dir)
    {
    case left:
        y -= 1;
        if (y < 0) stop = true;
        else if (ARR[x + 1][y] == 0) dir = down;
        break;
    case down:
        x += 1;
        if (x > rows) stop = true;
        else if (ARR[x][y + 1] == 0) dir = right;
        break;
    case right:
        y += 1;
        if (y >= rows) stop = true;
        else if (ARR[x - 1][y] == 0) dir = up;
        break;
    case up:
        x -= 1;
        if (x < 0) stop = true;
        else if (ARR[x][y - 1] == 0) dir = left;
    }
    if (stop) break;
}
}

В main.cpp файле все хорошо. Однако, в direct.cpp файле (моей функции) выбивают ошибки «expression must have pointer-to-object type» и переменные «x» и «y» внутри цикла «for» подчеркиваются красным, так что проблема в них.
Что я делаю не так? И как мне это исправить?

See more:

#include <stdio.h>
int i, n;
struct add_stock
{
    char fullname[30];
    int stocks;
    char com_name[30];
    int shares;
    float price;
    float total;
    int totalmoney;

} add;
int main()
{

    printf("Enter full name : ");
    scanf(" %[^n]s", add.fullname);
    printf("Enter the no. of stocks you want to purchased : ");
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {

        printf("Enter the name of the company : ");
        scanf(" %[^n]s", add[i].com_name);

        printf("Enter the no. of shares you want to purchased : ");
        scanf("%d", &add[i].shares);

        printf("Enter the price of each share  : ");
        scanf("%f", &add[i].price);

        add.total = add.shares * add.price;

        printf("Toatl money invested in this stock : ");
        scanf("%f", &add[i].total);
    }
    printf("Total money invested : ");
    scanf("%d", add.totalmoney);

    return 0;
}

What I have tried:

In question it’s add_stock , not add stock , i write like this becoz it’s not accepting question.
So, i get error for «add» saying subscripted value is neither array nor pointer nor vector.


Your struct add is a single structure but you are trying to refer to items as if it was an array. You will need to allocate space for the number of stock structures after you get the number form the user. Something like:#

struct add_stock* stocks = (struct add_stock*)malloc(sizeof(struct add_stock) * i);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

  • Forum
  • Beginners
  • pointer-to-object type?

pointer-to-object type?

Wrote my code and got a squiggly line, and not sure what it means. I’ve underlined where the error is referenced in the code. It’s line 37.

Error Message: «Expression must have pointer-to-object type.»

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//Global Declarations: Functions
string pName;

int main()
{
	string name[100]; //Array for name entries
	double score[100]; //Array for the scores
	double avgScr = 0; //score average
	int totalPlayers = 0; //total number of players
	
	displayData(name[100], score[100]);
}

void displayData(string &name, double &score)
{
	int x = 0;
	while (x <= 99)
	{
		cout << "Player name (Q to quit): "; //name
		cin >> name[x];

		//Quit Options 
		switch (name[x]) 
		{
		case 'Q': break;
		case 'q': break;
		default: x = x;
		}

		cout << "nPlayer score: "; //score
		cin >> score[x];
		x++;
	}

}

Last edited on

You are passing single values instead of entire arrays. Also, index 100 is out of bounds — the indexes of your arrays are from 0 to 99.

Look up how to pass arrays to functions.

Last edited on

Thanks for pointing that out, I thought that because arrays start at 0 that x would have to be 99, and I thought we had to declare the total number of spaces in the beginning.

Last edited on

So, I made a bit of progress, but not much. I figured out how to carry over the array, but now I have more errors. Underlined the errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//main function
int main()
{
	string name[100]; //Array for name entries
	double score[100] = { 0 }; //Array for the scores
	double avgScr = 0; //score average
	int x = 0;
	int totalPlayers = 0; //total number of players
	
	displayData(name[], score[]); //call to function:: Errors here are about expecting an expression.
}

//Input and Display name and score
void displayData(string name[], double score[], int x) 
{
	for (int x = 0; x <= 99; x++)
	{
		cout << "Player name (Q to quit): "; //name
		cin >> name[x];

		//Quit Options 
		switch (name[x]) //Error here must have integral or enum type
		{
		case 'Q': break; //Errors here have char type instead of string
		case 'q': break;
		default: 
			cout << "nPlayer Score: ";
			cin >> score[x];
		}
	}

}

Last edited on

On line 16 you’re still not passing the arrays correctly — remove the [] completely.

On line 28, you cannot switch on strings. Use if,else-if statements instead.

Last edited on

Darn it. Thank you for your help. But, on line 20, I still keep the brackets, correct?

Yes, just be aware though that as a parameter or return type, double score[] will degrade to double *score. It’s a weird carry-over from C, but it does what you want.

Last edited on

Cool. Thank you for your help and explanations!

Topic archived. No new replies allowed.

wist-007

0 / 0 / 0

Регистрация: 13.07.2016

Сообщений: 17

1

13.07.2016, 09:19. Показов 11358. Ответов 8

Метки нет (Все метки)


C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "stdafx.h"
#include <iostream>
#include "math.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{   int size, mas;
    setlocale(LC_ALL, "Rus");
    for (int sum, v = 0; v<size; v++)
    {       sum = 0;
    for (int w = 0;  w < size; w++)
    {
        if (mas [w][v]) sum += mas[w][v];
    }
        if (sum)
            cout << "Сумма строки" << v << " равен " << sum << endl;    }
    system("PAUSE");
    return 0;     }

Проблема заключается в том, что не видит J в строке, где написан mas [w][v] .
Прошу помочь найти проблему

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



zss

Модератор

Эксперт С++

12641 / 10135 / 6102

Регистрация: 18.12.2011

Сообщений: 27,170

13.07.2016, 09:28

2

Лучший ответ Сообщение было отмечено wist-007 как решение

Решение

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main()
{   
    const int size=10;
    int mas[size][size];
    setlocale(LC_ALL, "Rus");
    for (int v = 0; v<size; v++)
        for (int w = 0;  w < size; w++)
            mas[v][w]=rand()%10;
    for (int v = 0; v<size; v++)
    {       
        int sum = 0;
        for (int w = 0;  w < size; w++)
        {
            sum += mas[v][w];
        }
        cout << "Сумма строки" << v << " равна " << sum << endl;    
    }
    system("PAUSE");
    return 0;     
}



1



0 / 0 / 0

Регистрация: 13.07.2016

Сообщений: 17

13.07.2016, 09:33

 [ТС]

3

Спасибо, а как нужно сделать, чтоб были не рандомные значения, а те, которые впишу?



0



zss

Модератор

Эксперт С++

12641 / 10135 / 6102

Регистрация: 18.12.2011

Сообщений: 27,170

13.07.2016, 09:40

4

Не понял вопрос. Куда надо записать сумму строки, в другой массив?

C++
1
2
3
4
5
6
7
8
9
10
    int sum[size];
    for (int v = 0; v<size; v++)
    {       
        sum[v]=0;
        for (int w = 0;  w < size; w++)
        {
            sum[v] += mas[v][w];
        }
        cout << "Сумма строки" << v << " равна " << sum[v] << endl;    
    }

p.s. Не используйте v,w в качестве индексов.
Для этого рекомендованы i,j,k,l,m,n



1



0 / 0 / 0

Регистрация: 13.07.2016

Сообщений: 17

13.07.2016, 09:42

 [ТС]

5

Нужно чтоб я сам вписал значения в этот массив, а не рандомные числа.



0



zss

Модератор

Эксперт С++

12641 / 10135 / 6102

Регистрация: 18.12.2011

Сообщений: 27,170

13.07.2016, 09:46

6

C++
1
2
3
4
5
6
   for (int v = 0; v<size; v++)
        for (int w = 0;  w < size; w++)
        {
            cout<<"Enter mas["<<v<<"]["<<w<<"]:";
            cin>>mas[v][w];
         }



1



wist-007

0 / 0 / 0

Регистрация: 13.07.2016

Сообщений: 17

13.07.2016, 10:01

 [ТС]

7

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
    const int size = 5;
    int mas[size][size];
    setlocale(LC_ALL, "Rus");
    for (int v = 0; v<size; v++)
    for (int w = 0; w < size; w++)
    {
        {
            cout << "Enter mas[" << v << "][" << w << "]:";
            cin >> mas[v][w];
        }
        int sum=0 ;
        sum += mas[v][w];
        cout << "Сумма строки " << v << " равна " << sum << endl;
    }
    system("PAUSE");
    return 0;
}

Сделал как Вы показали, но проблема в том, что она не считает всю строку, а только каждый элемент. Ввожу 3- сразу 3 даёт ответ, хотя должен был вводить к примеру 5 цифр, если размерность 5.



0



zss

Модератор

Эксперт С++

12641 / 10135 / 6102

Регистрация: 18.12.2011

Сообщений: 27,170

13.07.2016, 10:05

8

Лучший ответ Сообщение было отмечено wist-007 как решение

Решение

Не смешивайте божий дар с яичницей.
Сначала все введите, а потом считайте!

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
for (int v = 0; v<size; v++)
    for (int w = 0; w < size; w++)
    {
            cout << "Enter mas[" << v << "][" << w << "]:";
            cin >> mas[v][w];
    }
for (int v = 0; v<size; v++)
{
    int sum=0 ;
    for (int w = 0; w < size; w++)
    {
        sum += mas[v][w];
     }
     cout << "Сумма строки " << v << " равна " << sum << endl;
}



1



0 / 0 / 0

Регистрация: 13.07.2016

Сообщений: 17

13.07.2016, 10:08

 [ТС]

9

Большое спасибо, получилось



0



  1. 09-29-2013


    #1

    BarakaMaiseli is offline


    Registered User

    BarakaMaiseli's Avatar


    Lightbulb error: expression must have pointer-to-object type

    I am passing two 2D arrays, along with other variables, from the main() function to a function defined as:

    Code:

    float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage,float kernel[][5], int image[][15])
    {
    ..........
    ..........
    float imageConvolved;
    float sum;
    int kernelSize=5;
    imageConvolved[i-kernelSize/2][j-kernelSize/2] = sum;
    return(imageConvolved);
    }

    The main function is defined as:

    Code:

    int main()
    {
    float gauss[5][5]={
                              {.........},
                              {.........},
                               ..........
                              {.........}
                             };
    int img[15][15]={
                           {.......},
                           {.......},
                            .........
                           {.......}
                          };
    int rowsK = 5,colsK = 5,rowsI = 15,colsI = 15;
    float result;
    result = conv2D(rowsK, colsK, rowsI, colsI, gauss, img);
    return 0;
    }

    When I compile this code using CCStudio V3.3 I get an error » error: expression must have pointer-to-object type» and a warning «warning: variable «result» was set but never used». The error points to the function conv2D in the line:
    imageConvolved[i-kernelSize/2][j-kernelSize/2] = sum.

    I have been struggling through the knowledge I am having in C programming and also through various posts online but none of the post has solved my problem. I tried using the GCC v4.7.3 compiler in UBUNTU but I am getting an error in the same line, the error says:
    «error: subscripted value is neither array nor pointer nor vector«
    Please, if someone has a link or explanations to the sources of these errors in my code kindly share it.

    The complete code is:

    Code:

    #include<stdio.h>
    #include<math.h>
    
    float conv2D(int, int, int, int,float kernel[][5], int image[][15]);//Function Prototype definition
    
    float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage,float kernel[][5], int image[][15])
    {
    int kernelSize;//This variable represents the size of the Gaussian kernel
    int i; //variable which controls the rows of an image
    int j; //variable which controls the columns of an image
    int ii; //variable which controls the rows of the kernel
    int jj;//variable which controls the columns of the kernel
    float sum;//variable that holds the result of convolution for a particular pixel of an image
    float imageConvolved;//Result of an image convolved by a Gaussian kernel
    int imagePixel;
    float kernelPixel;
    kernelSize = colsKernel;/*Since we consider a square kernel, then rowsKernel=colsKernel, which implies that the size of the kernel (kernelSize) equals either of these two variables (that is, kernelSize=colsKernel=rowsKernel)*/
    for (i =  kernelSize/ 2; i < rowsImage - kernelSize / 2; i++) // perform iteration through the rows of an image
    {
      for (j = kernelSize / 2; j < colsImage - kernelSize / 2; j++) // perform iteration through the columns of an image
      {
        sum = 0; /*Initializing the accumulator. This variable will finally contain the convolution result for a particular pixel*/
        for (ii = - kernelSize / 2; ii <= kernelSize / 2; ii++) // perform iteration through the rows of a kernel
        {
          for (jj = - kernelSize / 2; jj <= kernelSize / 2; jj++) //perform iteration through the columns of a kernel
          {
            imagePixel = image[i + ii][j +jj];
            kernelPixel = kernel[ii + kernelSize / 2][jj + kernelSize / 2];
    
            sum += imagePixel * kernelPixel;
          }
        }
        imageConvolved[i-kernelSize/2][j-kernelSize/2] = sum; 
      }
    }
    return(imageConvolved);// convolved image
    }
    
    int main()
    {
    float gauss[][5]={
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1}
               };
    int img[][15]={
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
              };
    int rowsK = 5,colsK = 5,rowsI = 15,colsI = 15;
    float result;
    result = conv2D(rowsK, colsK, rowsI, colsI, gauss, img);
    return 0;
    }

    Last edited by BarakaMaiseli; 09-29-2013 at 09:38 PM.


  2. 09-29-2013


    #2

    Salem is online now


    and the hat of int overfl

    Salem's Avatar


    > float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage,float kernel[][5], int image[][15])
    You’re returning a scalar value.

    > float imageConvolved;//Result of an image convolved by a Gaussian kernel
    You’re declaring a scalar value.

    > imageConvolved[i-kernelSize/2][j-kernelSize/2] = sum;
    Now you’re trying to make it into an array of some sort (this won’t work).

    > return(imageConvolved);// convolved image
    And finally, you’re returning a scalar.

    Now, if you really want to return an array, the best (easiest) thing to do is this.
    void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage,float kernel[][5], int image[][15], imageConvolved[][5])
    Then pass a result array from main, in the same way you pass existing array parameters.


  3. 09-30-2013


    #3

    BarakaMaiseli is offline


    Registered User

    BarakaMaiseli's Avatar


    Thank you for your response.
    I have tried to follow the comments, but I am still getting similar errors. Below is the code after I did follow the comments:

    Code:

    #include<stdio.h>
    #include<math.h>
    
    float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float imageConvolved[][11]);//Function Prototype definition
    
    float conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float imageConvolved[][11])
    {
    int kernelSize;//This variable represents the size of the Gaussian kernel
    int i; //variable which controls the rows of an image
    int j; //variable which controls the columns of an image
    int ii; //variable which controls the rows of the kernel
    int jj;//variable which controls the columns of the kernel
    float sum;//variable that holds the result of convolution for a particular pixel of an image
    int imagePixel;
    float kernelPixel;
    kernelSize = colsKernel;/*Since we consider a square kernel, then rowsKernel=colsKernel, which implies that the size of the                 kernel (kernelSize) equals either of these two variables (that is, kernelSize=colsKernel=rowsKernel)*/
    for (i =  kernelSize/ 2; i < rowsImage - kernelSize / 2; i++) // perform iteration through the rows of an image
    {
      for (j = kernelSize / 2; j < colsImage - kernelSize / 2; j++) // perform iteration through the columns of an image
      {
        sum = 0; /*Initializing the accumulator. This variable will finally contain the convolution result for a particular pixel*/
        for (ii = - kernelSize / 2; ii <= kernelSize / 2; ii++) // perform iteration through the rows of a kernel
        {
          for (jj = - kernelSize / 2; jj <= kernelSize / 2; jj++) //perform iteration through the columns of a kernel
          {
            imagePixel = image[i + ii][j +jj];
            kernelPixel = kernel[ii + kernelSize / 2][jj + kernelSize / 2];
    
            sum += imagePixel * kernelPixel;
          }
        }
        imageConvolved[i-kernelSize/2][j-kernelSize/2] = sum; 
      }
    }
    return(imageConvolved);// convolved image
    }
    
    int main()
    {
    float gauss[][5]={
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1}
               };
    int img[][15]={
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
              };
    int rowsK = 5,colsK = 5,rowsI = 15,colsI = 15;
    float result[11][11];
    float Iconv;
    Iconv = conv2D(rowsK, colsK, rowsI, colsI, gauss, img, result);
    return 0;
    }

    The error the CCS compiler reports is:
    «convolution.c», line 39: error: return value type does not match the function type
    «convolution.c», line 70: warning: variable «Iconv» was set but never used

    The lines listed points to the function conv2D in the line

    return(imageConvolved);// convolved image
    and the main() function in the line float Iconv;, respectively.

    If I declare the variable Iconv in the main() function as an array, that is float Iconv[11][11];, the warning (that

    variable «Iconv» was set but never used) disappear, but I am getting another two errors as a result:«convolution.c», line 39: error: return value type does not match the function type
    «convolution.c», line 71: error: expression must be a modifiable lvalue


  4. 09-30-2013


    #4

    grumpy is offline


    Registered User


    An array is not magically converted to a single value, or vice versa. That explains the errors. imageConvolved is specifed as a 2D array (in the function arguments). The function returns a single float value. Hence the complaint about return value type not matching function type (and the error you get when you change IConv to be an array — the compiler believes you are trying to store a single float value as an array).

    The warning is simply means you assign the return value from the function to a variable, but then never subsequently use that variable.

    Right 98% of the time, and don’t care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.


  5. 09-30-2013


    #5

    Salem is online now


    and the hat of int overfl

    Salem's Avatar


    So if you make the function return void, remove the return statement and the return result assignments in main, does it work?

    The whole image result will be in your 11×11 result array.


  6. 09-30-2013


    #6

    BarakaMaiseli is offline


    Registered User

    BarakaMaiseli's Avatar


    Thanks for the comments. Very useful…! It is now working (in the GCC compiler under UBUNTU environment), and below is a complete code:

    Code:

    //#include"standard_library.h"
    //#include"SuperResolution.h"
    
    #include<stdio.h>
    #include<math.h>
    
    void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float res[][11]);//Function Prototype definition
    
    void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float res[][11])
    {
    int kernelSize;//This variable represents the size of the Gaussian kernel
    int i; //variable which controls the rows of an image
    int j; //variable which controls the columns of an image
    int ii; //variable which controls the rows of the kernel
    int jj;//variable which controls the columns of the kernel
    float sum;//variable that holds the result of convolution for a particular pixel of an image
    //float imageConvolved;//Result of an image convolved by a Gaussian kernel
    int imagePixel;
    float kernelPixel;
    //float imageConvolved[11][11];
    kernelSize = colsKernel;/*Since we consider a square kernel, then rowsKernel=colsKernel, which implies that the size of the                 kernel (kernelSize) equals either of these two variables (that is, kernelSize=colsKernel=rowsKernel)*/
    for (i =  kernelSize/ 2; i < rowsImage - kernelSize / 2; i++) // perform iteration through the rows of an image
    {
      for (j = kernelSize / 2; j < colsImage - kernelSize / 2; j++) // perform iteration through the columns of an image
      {
        sum = 0; /*Initializing the accumulator. This variable will finally contain the convolution result for a particular pixel*/
        for (ii = - kernelSize / 2; ii <= kernelSize / 2; ii++) // perform iteration through the rows of a kernel
        {
          for (jj = - kernelSize / 2; jj <= kernelSize / 2; jj++) //perform iteration through the columns of a kernel
          {
            imagePixel = image[i + ii][j +jj];
            kernelPixel = kernel[ii + kernelSize / 2][jj + kernelSize / 2];
    
            sum += imagePixel * kernelPixel;
          }
        }
        res[i-kernelSize/2][j-kernelSize/2] = sum; 
      }
    }
    //res=imageConvolved;
    //return(imageConvolved);// convolved image
    }
    
    int main()
    {
    float gauss[][5]={
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1},
                {1, 1, 1, 1, 1}
               };
    int img[][15]={
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
              };
    int rowsK = 5,colsK = 5,rowsI = 15,colsI = 15;
    float res[11][11];
    //float Iconv[11][11];
    int i,j,m,n;
    for(i=0;i<11;i++)
    for(j=0;j<11;j++)
    res[i][j]=0.0;
    conv2D(rowsK, colsK, rowsI, colsI, gauss, img,res);
    for(m=0;m<11;m++)
    for(n=0;n<11;n++)
    {
    printf("%4.0f",res[m][n]);
    if(n==10)
    printf("n");
    }
    return 0;
    }

    The result when compiled and run is:
    error: expression must have pointer-to-object type-convolution-png
    This code explains the convolution of an image with a kernel. The indicated matrices, however, can be replaced by real matrices (The convolution kernel and image).

    In the CCStudio V3.3, however, I am still getting some errors when I compile, and I am still struggling on getting a way forward. Here are the errors in the CCStudio:
    ———————— super_resolution.pjt — Debug ————————
    [convolution.c] «C:CCStudio_v3.3C6000cgtoolsbincl6x» -g -pdsw225 -fr»C:/Documents and Settings/Administrator/Desktop/testPrograms/super_resolution/Debug» -d»_DEBUG» -mv6400 -@»Debug.lkf» «convolution.c»

    Warning: The project has no cmd file while the Text Linker is selected
    [Linking…] «C:CCStudio_v3.3C6000cgtoolsbincl6x» -@»Debug.lkf»
    <Linking>
    >> warning: entry point symbol _c_int00 undefined

    undefined first referenced
    symbol in file
    ——— —————-
    __mpyf C:\Documents and Settings\Administrator\Desktop\testPrograms\su per_resolution\Debug\convolution.obj
    __addf C:\Documents and Settings\Administrator\Desktop\testPrograms\su per_resolution\Debug\convolution.obj
    __strasgi C:\Documents and Settings\Administrator\Desktop\testPrograms\su per_resolution\Debug\convolution.obj
    __fltif C:\Documents and Settings\Administrator\Desktop\testPrograms\su per_resolution\Debug\convolution.obj
    >> error: symbol referencing errors — ‘./Debug/super_resolution.out’ not built

    >> Compilation failure

    Build Complete,
    2 Errors, 2 Warnings, 0 Remarks.

    I am thinking that I the problem may be caused by the settings of my compiler, or something is wrong with the linking of the files during the compilation process.


  7. 09-30-2013


    #7

    Salem is online now


    and the hat of int overfl

    Salem's Avatar


    > In the CCStudio V3.3, however, I am still getting some errors when I compile, and I am still struggling on getting a way forward. Here are the errors in the CCStudio:
    Those are link errors, not compile errors.

    Since your code uses just standard C, the easy thing would be to just create a new console project and copy/paste your code into it.


  8. 10-02-2013


    #8

    BarakaMaiseli is offline


    Registered User

    BarakaMaiseli's Avatar


    Great…!! Now it works, and it can also be used for anyone who would like to convolve 2D matrices. A slight modification can be done if one needs to convolve an image with a Gaussian Kernel, since the given matrices a constant (used for testing purposes). My next movie is to perform the convolution using real data.
    Here are the source codes:

    main.c

    Code:

    #include"standard_library.h"
    #include"SuperResolution.h"
    
    int main()
    {
    int rowsK = 5,colsK = 5,rowsI = 15,colsI = 15;
    float res[11][11];
    int i,j,m,n;
    for(i=0;i<11;i++)
    for(j=0;j<11;j++)
    res[i][j]=0.0;
    conv2D(rowsK, colsK, rowsI, colsI, gauss, img,res);
    for(m=0;m<11;m++)
    for(n=0;n<11;n++)
    {
    printf("%4.0f",res[m][n]);
    if(n==10)
    printf("n");
    }
    return 0;
    }

    conv.c

    Code:

    void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float res[][11])
    {
    int kernelSize;//This variable represents the size of the Gaussian kernel
    int i; //variable which controls the rows of an image
    int j; //variable which controls the columns of an image
    int ii; //variable which controls the rows of the kernel
    int jj;//variable which controls the columns of the kernel
    float sum;//variable that holds the result of convolution for a particular pixel of an image
    //float imageConvolved;//Result of an image convolved by a Gaussian kernel
    int imagePixel;
    float kernelPixel;
    //float imageConvolved[11][11];
    kernelSize = colsKernel;/*Since we consider a square kernel, then rowsKernel=colsKernel, which implies that the size of the                 kernel (kernelSize) equals either of these two variables (that is, kernelSize=colsKernel=rowsKernel)*/
    for (i =  kernelSize/ 2; i < rowsImage - kernelSize / 2; i++) // perform iteration through the rows of an image
    {
      for (j = kernelSize / 2; j < colsImage - kernelSize / 2; j++) // perform iteration through the columns of an image
      {
        sum = 0; /*Initializing the accumulator. This variable will finally contain the convolution result for a particular pixel*/
        for (ii = - kernelSize / 2; ii <= kernelSize / 2; ii++) // perform iteration through the rows of a kernel
        {
          for (jj = - kernelSize / 2; jj <= kernelSize / 2; jj++) //perform iteration through the columns of a kernel
          {
            imagePixel = image[i + ii][j +jj];
            kernelPixel = kernel[ii + kernelSize / 2][jj + kernelSize / 2];
    
            sum += imagePixel * kernelPixel;
          }
        }
        res[i-kernelSize/2][j-kernelSize/2] = sum; 
      }
    }
    }

    SuperResolution.h

    Code:

    #ifndef _SUPERRESOLUTION_H
    #define _SUPERRESOLUTION_H
    
    void conv2D(int rowsKernel, int colsKernel, int rowsImage, int colsImage, float kernel[][5], int image[][15], float res[][11]);//Function Prototype definition
    
    float gauss[][5]={
                {1, 2, 4, 2, 1},
                {2, 1, 1, 1, 2},
                {4, 8, 8, 8, 4},
                {2, 1, 1, 1, 2},
                {1, 2, 4, 2, 1}
               };
    int img[][15]={
               {1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
               {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
              };
    #endif

    standard_library.h

    Code:

    #ifndef _STANDARD_LIBRARY_H
    #define _STANDARD_LIBRARY_H
    
    //Include standard header files
    #include<math.h>
    #include<stdio.h>
    #endif

    RESULT
    error: expression must have pointer-to-object type-result-png

    Note that the result of convolution is not the same size as the original convoluting matrix because of cropping at the boundaries. This is one way of implementing convolution, although there are other ways which keep the two matrices (convoluting matrix and result) the same in dimension.


  • Remove From My Forums
  • Question

  • Hi,

      I’m using Visual Studio 2017 to set up an image array.  I have written most of the routines but one gives me the error in the title line.  I have searched everywhere for a possible solution but I have not been able to solve it yet. 
    There are 2 files: NS32.h and MyMain.cpp.  The essential code is:

    NS32.h:

    #pragma once
    
    #include <Windows.h>
    
    namespace NS32 {
    
    	public ref class PictureBoxArray : public CollectionBase
    	{
    	public:
    		System::Windows::Forms::PictureBox^ AddNewPictureBox(Panel ^HostPanel, int Info)
    			{
    	//  Routine to add a PictureBox item to a PictureBox array.
    			System::Windows::Forms::PictureBox ^aPictureBox = gcnew System::Windows::Forms::PictureBox();
    	//	Add the button to the collection's internal list.
    			this->List->Add(aPictureBox);
    	//	Add the label to the controls collection of the form referenced by the HostPanel field.
    			HostPanel->Controls->Add(aPictureBox);
    	//	Set initial PictureBox element properties.
    			aPictureBox->Top = Info;
    			aPictureBox->Width = 28;		
    			aPictureBox->Enabled = false;
    			aPictureBox->Visible = false;
    			int Cou = PictureBoxArray::Count - 1;
    			aPictureBox->Tag = Cou;
    			aPictureBox->Left = Info + Cou * 28;
    			return aPictureBox;
    			}
    
    		property int Item[int]
    			{
    			int get(int index)
    				{
    				return ((int) (List[index]));
    				}
    
    			void set(int index, int value)
    				{
    				List[index] = value;
    				}
    			}
    	};			// End of  Class  PictureBoxArray  //
    
    	public ref class fgl : public System::Windows::Forms::Form
    	{
    		//#Region "Windows Form Designer generated code "
    	public:
    		virtual ~fgl()
    		{
    			this->Dispose(true);
    			delete components;
    			delete pd;
    		}
    
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
    
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		//void InitializeComponent();
    		void InitializeComponent()
    		{
    		};
    
    	public:
    		static PictureBoxArray^ pd = gcnew PictureBoxArray;			// Picture Box Array.
    
    	};			// End of  Class  fgl  //
    
    }			// End of  NameSpace  NS32  //
    
    

    The error appears in MyMain.cpp:

    #include "NS32.h"
    
    namespace NS32 {
    
    	void ShowPics(std::vector<bool> &Table)
    	{
    
    using NS32::fgl;
    
    		for (int i = 0; i <= 8; i++)
    		{
    			if (Table[i])
    			{
    				NS32::fgl::pd[i]->Visible = true;
    // Error Here = E2242  expression must have pointer-to-object or handle-to-C++/CLI-array type
    			}
    		}
    	};
    }			// End of  NameSpace  NS32  //
    

    Any clues or pointers would be very welcome.  Many thanks.

Answers

  • pd is a pointer to the start of the array.  pd[i] is an element of the array.  In this case, you would use the «.» operator instead of the «->» operator.

    Why do you think there are 8 elements in the array?

    pd[i] has type pointer to PictureBoxArray.  Why do you think it contains a member named Visible?  The code in AddNewPictureBox would suggest not.

    Why are you deleting memory allocated with gcnew?

    • Marked as answer by

      Saturday, May 4, 2019 8:12 AM

  • I think that you should define a different property:

    public:
       property PictureBox^ default[int]
       {
          PictureBox ^ get( int index ) 
          {
             return (PictureBox^)List[index];
          }
    
          void set( int index, PictureBox ^ value )
          {
             List[index] = value;
          }
       }
    
    

    • Marked as answer by
      HotIndigo
      Saturday, May 4, 2019 8:12 AM

  • This particular routine deals with 8 elements only.  Pictureboxes have a property Visible.  The memory deletion is part of a destructor — I hadn’t removed all unnecessary code.

    In the code you posted, pd points to a single PictureBoxArray.  As far as pd is concerned, that is an array of one element, not eight.

    While a PictureBox has a member named Visible, pd points to a PictureBoxArray which is a different type of object than a PictureBox.  Look at how member Visible is used in your function AddNewPictureBox.

    • Marked as answer by
      HotIndigo
      Saturday, May 4, 2019 8:12 AM

  • This particular routine deals with 8 elements only.  Pictureboxes have a property Visible.  The memory deletion is part of a destructor — I hadn’t removed all unnecessary code.

    In the code you posted, pd points to a single PictureBoxArray.  As far as pd is concerned, that is an array of one element, not eight.

    While a PictureBox has a member named Visible, pd points to a PictureBoxArray which is a different type of object than a PictureBox.  Look at how member Visible is used in your function AddNewPictureBox.

    Maybe I have not defined PictureBoxArray correctly. Can I define a class as an array?  I had assumed
     : public CollectionBase  would have taken care of that.

    • Marked as answer by
      HotIndigo
      Saturday, May 4, 2019 8:11 AM

Member Avatar


Ancient Dragon

5,243




Achieved Level 70



Team Colleague



Featured Poster


10 Years Ago

Please post the Horse and Track classes.

Member Avatar

10 Years Ago

I somehow managed to fix the error by retyping the main code again, and the class errors were due to not defining the subscript in the header file.

However, after running the code, I realized the code does not work like I wanted it to. I could use some assistance on how to make this «Horse Race» just by simply running a horse by the inputted name and asterisks running across the screen one-by-one until they hit a certain value (I’d be doing 20), in which the code would declare a winner (which should already be programmed).

As it is:

#include"HorseRace.h"
#include<iostream>
#include<conio.h>
#include<ctime>
#include<string>
using namespace std;

int main()
{
    srand(time(NULL));
    int numhor=0, lane=0, runner=0, winlane=0;
    int tick[10];
    bool winner=false;
    string name;
    Horse HorseRace[10];
    Track TrackRace[10];
    cout<<"How many horses will you race? ";
    cin>>numhor;
    numhor=numhor+1;
    for(int n=0; n<numhor; n++)
    {
        system("cls");
        cout<<"Horse #"<<n<<endl;
        cout<<"Name the horse: ";
        getline(cin,name);
        int rename= atoi(name.c_str());
        HorseRace[n].nameHorse(rename);
        system("cls");
        HorseRace[n].lane(lane);
        TrackRace[n].fillTrack(HorseRace[n], lane);
    }
    system("cls");
    while(winner==false)
    {
        //code for running horses
    }
    for(int w=0; w<10; w++)
    {
        if(HorseRace[w].getlane()==winlane)
        {
            cout<<HorseRace[w].getname()<<" wins!"<<endl;
        }
    }
}

In my header file, the Horse class contains:

int name; //horse name
int position;

and Track class contains:

Horse track[10]; //lanes of track
int horseCount; //number of horses
int laneoccupy[10];

and the classes are the same as my earlier posts.

Edited

10 Years Ago
by ssh9411

Понравилась статья? Поделить с друзьями:
  • Error expression in new declarator must have integral or enumeration type
  • Error expression cannot be used as a function
  • Error expression assertion failed
  • Error exportarchive no signing certificate ios distribution found
  • Error failed building wheel for python ldap